首页 文章 精选 留言 我的

精选列表

搜索[ios],共10000篇文章
优秀的个人博客,低调大师

iOS:切换视图时,反向传递数据方法二:代理

代理: 1、发送信息的控制器设置一个代理,并自定义一个代理的方法,用来传递数据 2、接受信息的控制器遵循发送信息的控制器的协议 3、接受信息的控制器设置发送信息的控制器的代理为自己self 4、接受信息的控制器实现协议中的方法,即接受数据 首先将控制器通过modal(push)方式联接,同时设置segue的identifier标识,因为这个identifier是与目的控制器唯一的识别的方式,最后再进行代码操作。 1、所有文件: 2、让FirstViewController关联自己的类ViewController(.h/.m) 3、让SecondViewController关联自己的类SecondViewController(.h/.m) 4、设置segue的identifier标识 具体代码如下: FirstViewController控制器关联的ViewController类 1 #import "ViewController.h" 2 #import "SecondViewController.h" 3 4 @interface ViewController ()<SecondViewControllerDelegate> 5 @property (weak, nonatomic) IBOutlet UITextField *firstTextField; 6 7 @end 8 9 @implementation ViewController 10 11 - (void)viewDidLoad { 12 [super viewDidLoad]; 13 } 14 15 //重写该方法,视图切换时,自动调用 16 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 17 { 18 if([segue.identifier isEqualToString:@"modal"]) 19 { 20 //获取目的控制器 21 SecondViewController *secondVC = segue.destinationViewController; 22 23 //正向传数据 24 secondVC.information = self.firstTextField.text; 25 26 //设置代理 27 secondVC.delegate = self; 28 29 } 30 } 31 32 #pragma mark -<SecondViewControllerDelegate> 33 //反向接受信息 34 -(void)FinishedInformation:(SecondViewController *)secondVC andinfo:(NSString *)infos 35 { 36 self.firstTextField.text = infos; 37 } 38 @end SecondViewController控制器关联的SeconViewController类 1 #import "SecondViewController.h" 2 3 @interface SecondViewController () 4 @property (weak, nonatomic) IBOutlet UITextField *secondTextField; 5 6 @end 7 8 @implementation SecondViewController 9 //返回时的触发事件 10 - (IBAction)returnClicked:(UIBarButtonItem *)sender 11 { 12 //反向传递数据 13 [self.delegate FinishedInformation:self andinfo:self.secondTextField.text]; 14 15 //关闭模态窗口 16 [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; 17 //[self dismissViewControllerAnimated:YES completion:nil]; 18 } 19 20 - (void)viewDidLoad { 21 [super viewDidLoad]; 22 23 // 显示文本框内容(接受传递过来的数据) 24 self.secondTextField.text = self.information; 25 } 26 27 @end 程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式! 本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/4808528.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

30分钟搞定iOS自定义相机

最近公司的项目中用到了相机,由于不用系统的相机,UI给的相机切图,必须自定义才可以。就花时间简单研究了一下相机的自定义。 相机属于系统硬件,这就需要我们来手动调用iPhone的相机硬件,分为以下步骤: 2016-03-30 上午9.51.09.png 1、首先声明以下对象 #import <AVFoundation/AVFoundation.h> //捕获设备,通常是前置摄像头,后置摄像头,麦克风(音频输入) @property (nonatomic, strong) AVCaptureDevice *device; //AVCaptureDeviceInput 代表输入设备,他使用AVCaptureDevice 来初始化 @property (nonatomic, strong) AVCaptureDeviceInput *input; //输出图片 @property (nonatomic ,strong) AVCaptureStillImageOutput *imageOutput; //session:由他把输入输出结合在一起,并开始启动捕获设备(摄像头) @property (nonatomic, strong) AVCaptureSession *session; //图像预览层,实时显示捕获的图像 @property (nonatomic ,strong) AVCaptureVideoPreviewLayer *previewLayer; 2、初始化各个对象 - (void)cameraDistrict { // AVCaptureDevicePositionBack 后置摄像头 // AVCaptureDevicePositionFront 前置摄像头 self.device = [self cameraWithPosition:AVCaptureDevicePositionFront]; self.input = [[AVCaptureDeviceInput alloc] initWithDevice:self.device error:nil]; self.imageOutput = [[AVCaptureStillImageOutput alloc] init]; self.session = [[AVCaptureSession alloc] init]; // 拿到的图像的大小可以自行设定 // AVCaptureSessionPreset320x240 // AVCaptureSessionPreset352x288 // AVCaptureSessionPreset640x480 // AVCaptureSessionPreset960x540 // AVCaptureSessionPreset1280x720 // AVCaptureSessionPreset1920x1080 // AVCaptureSessionPreset3840x2160 self.session.sessionPreset = AVCaptureSessionPreset640x480; //输入输出设备结合 if ([self.session canAddInput:self.input]) { [self.session addInput:self.input]; } if ([self.session canAddOutput:self.imageOutput]) { [self.session addOutput:self.imageOutput]; } //预览层的生成 self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; self.previewLayer.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT-64); self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer:self.previewLayer]; //设备取景开始 [self.session startRunning]; if ([_device lockForConfiguration:nil]) { //自动闪光灯, if ([_device isFlashModeSupported:AVCaptureFlashModeAuto]) { [_device setFlashMode:AVCaptureFlashModeAuto]; } //自动白平衡,但是好像一直都进不去 if ([_device isWhiteBalanceModeSupported:AVCaptureWhiteBalanceModeAutoWhiteBalance]) { [_device setWhiteBalanceMode:AVCaptureWhiteBalanceModeAutoWhiteBalance]; } [_device unlockForConfiguration]; } } 根据前后置位置拿到相应的摄像头: - (AVCaptureDevice *)cameraWithPosition:(AVCaptureDevicePosition)position{ NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; for ( AVCaptureDevice *device in devices ) if ( device.position == position ){ return device; } return nil; } 3、拍照拿到相应图片: - (void)photoBtnDidClick { AVCaptureConnection *conntion = [self.imageOutput connectionWithMediaType:AVMediaTypeVideo]; if (!conntion) { NSLog(@"拍照失败!"); return; } [self.imageOutput captureStillImageAsynchronouslyFromConnection:conntion completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { if (imageDataSampleBuffer == nil) { return ; } NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; self.image = [UIImage imageWithData:imageData]; [self.session stopRunning]; [self.view addSubview:self.cameraImageView]; } 4、保存照片到相册: #pragma - 保存至相册 - (void)saveImageToPhotoAlbum:(UIImage*)savedImage { UIImageWriteToSavedPhotosAlbum(savedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); } // 指定回调方法 - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo { NSString *msg = nil ; if(error != NULL){ msg = @"保存图片失败" ; }else{ msg = @"保存图片成功" ; } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存图片结果提示" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } 5、前后置摄像头的切换 - (void)changeCamera{ NSUInteger cameraCount = [[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] count]; if (cameraCount > 1) { NSError *error; //给摄像头的切换添加翻转动画 CATransition *animation = [CATransition animation]; animation.duration = .5f; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.type = @"oglFlip"; AVCaptureDevice *newCamera = nil; AVCaptureDeviceInput *newInput = nil; //拿到另外一个摄像头位置 AVCaptureDevicePosition position = [[_input device] position]; if (position == AVCaptureDevicePositionFront){ newCamera = [self cameraWithPosition:AVCaptureDevicePositionBack]; animation.subtype = kCATransitionFromLeft;//动画翻转方向 } else { newCamera = [self cameraWithPosition:AVCaptureDevicePositionFront]; animation.subtype = kCATransitionFromRight;//动画翻转方向 } //生成新的输入 newInput = [AVCaptureDeviceInput deviceInputWithDevice:newCamera error:nil]; [self.previewLayer addAnimation:animation forKey:nil]; if (newInput != nil) { [self.session beginConfiguration]; [self.session removeInput:self.input]; if ([self.session canAddInput:newInput]) { [self.session addInput:newInput]; self.input = newInput; } else { [self.session addInput:self.input]; } [self.session commitConfiguration]; } else if (error) { NSLog(@"toggle carema failed, error = %@", error); } } } 6、相机的其它参数设置 //AVCaptureFlashMode 闪光灯 //AVCaptureFocusMode 对焦 //AVCaptureExposureMode 曝光 //AVCaptureWhiteBalanceMode 白平衡 //闪光灯和白平衡可以在生成相机时候设置 //曝光要根据对焦点的光线状况而决定,所以和对焦一块写 //point为点击的位置 - (void)focusAtPoint:(CGPoint)point{ CGSize size = self.view.bounds.size; CGPoint focusPoint = CGPointMake( point.y /size.height ,1-point.x/size.width ); NSError *error; if ([self.device lockForConfiguration:&error]) { //对焦模式和对焦点 if ([self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) { [self.device setFocusPointOfInterest:focusPoint]; [self.device setFocusMode:AVCaptureFocusModeAutoFocus]; } //曝光模式和曝光点 if ([self.device isExposureModeSupported:AVCaptureExposureModeAutoExpose ]) { [self.device setExposurePointOfInterest:focusPoint]; [self.device setExposureMode:AVCaptureExposureModeAutoExpose]; } [self.device unlockForConfiguration]; //设置对焦动画 _focusView.center = point; _focusView.hidden = NO; [UIView animateWithDuration:0.3 animations:^{ _focusView.transform = CGAffineTransformMakeScale(1.25, 1.25); }completion:^(BOOL finished) { [UIView animateWithDuration:0.5 animations:^{ _focusView.transform = CGAffineTransformIdentity; } completion:^(BOOL finished) { _focusView.hidden = YES; }]; }]; } } 7、遇到的一些坑和解决办法 1) 前后置摄像头的切换 前后值不能切换,各种尝试找了半天没找到有原因。后来发现我在设置图片尺寸的时候设置为1080P [self.session canSetSessionPreset: AVCaptureSessionPreset1920x1080] ,前置摄像头并不支持这么大的尺寸,所以就不能切换前置摄像头。我验证了下 前置摄像头最高支持720P,720P以内可自由切换。 当然也可以在前后置摄像头切换的时候,根据前后摄像头来设置不同的尺寸,这里不在赘述。 2)焦点位置 CGPoint focusPoint = CGPointMake( point.y /size.height ,1-point.x/size.width ); setExposurePointOfInterest:focusPoint 函数后面Point取值范围是取景框左上角(0,0)到取景框右下角(1,1)之间。官方是这么写的: The value of this property is a CGPoint that determines the receiver's focus point of interest, if it has one. A value of (0,0) indicates that the camera should focus on the top left corner of the image, while a value of (1,1) indicates that it should focus on the bottom right. The default value is (0.5,0.5). 我也试了按这个来但位置就是不对,只能按上面的写法才可以。前面是点击位置的y/PreviewLayer的高度,后面是1-点击位置的x/PreviewLayer的宽度 3)对焦和曝光 我在设置对焦是 先设置了模式setFocusMode,后设置对焦位置,就会导致很奇怪的现象,对焦位置是你上次点击的位置。所以一定要先设置位置,再设置对焦模式。 曝光同上

优秀的个人博客,低调大师

PNChart,简洁高效有动画效果的iOS图表库

导入 pod导入相对简单,要手动导入这个库,先下载下来(https://github.com/kevinzhow/PNChart),解压后把PNChart文件夹拖入工程中 运行发现#import"PNRadarChartDataItem.h"报红,在它的.h文件里引入#import<UIKit/UIKit.h>头文件;#import<UICountingLabel/UICountingLabel.h>报错,下载UICountingLabel(https://github.com/dataxpress/UICountingLabel)解压后把UICountingLabel的.m和.h文件拖入工程,把报错的#import<UICountingLabel/UICountingLabel.h>头文件换为#import"UICountingLabel.h" 项目中引用头文件#import"PNChart.h" 折线图 PNLineChart * lineChart = [[PNLineChartalloc]initWithFrame:CGRectMake(0,135.0,SCREEN_WIDTH,200.0)]; //X轴数据 [lineChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]]; //Y轴数据 NSArray * data01Array =@[@60.1,@160.1,@126.4,@262.2,@186.2]; PNLineChartData *data01 = [PNLineChartDatanew]; data01.color = PNFreshGreen; data01.itemCount = lineChart.xLabels.count; data01.getData = ^(NSUInteger index) { CGFloat yValue = [data01Array[index] floatValue]; return [PNLineChartDataItemdataItemWithY:yValue]; }; //可以添加多条折线 NSArray * data02Array =@[@20.1,@180.1,@26.4,@202.2,@126.2]; PNLineChartData *data02 = [PNLineChartDatanew]; data02.color = PNTwitterColor; data02.itemCount = lineChart.xLabels.count; data02.getData = ^(NSUInteger index) { CGFloat yValue = [data02Array[index] floatValue]; return [PNLineChartDataItemdataItemWithY:yValue]; }; lineChart.chartData = @[data01, data02]; [lineChart strokeChart]; //加载在视图上 [self.windowaddSubview:lineChart]; 柱状图 PNBarChart * barChart = [[PNBarChartalloc]initWithFrame:CGRectMake(0,135.0,SCREEN_WIDTH,200.0)]; //X轴数据 [barChart setXLabels:@[@"SEP 1",@"SEP 2",@"SEP 3",@"SEP 4",@"SEP 5"]]; //Y轴数据 [barChart setYValues:@[@1, @10,@2,@6,@3]]; [barChart strokeChart]; //加载在视图上 [self.windowaddSubview:barChart]; 饼状图 PNPieChart *pieChart = [[PNPieChartalloc]initWithFrame:CGRectMake(40.0,155.0,240.0,240.0)items:items]; //饼状图文字颜色 pieChart.descriptionTextColor = [UIColorwhiteColor]; pieChart.descriptionTextFont = [UIFontfontWithName:@"Avenir-Medium"size:14.0]; //绘制 [pieChart strokeChart]; //加载在视图上 [self.windowaddSubview:pieChart]; 圆形进度条 // total参数是进度条的总数据量,current是当前的数据量,closewise是绘制方向,YES是从左到右,NO为从右到左 PNCircleChart *circleChart = [[PNCircleChartalloc]initWithFrame:CGRectMake(40.0,155.0,240.0,240.0)total:@100current:@30clockwise:NO]; //绘制图形 [circleChart strokeChart]; //加载在视图上 [self.windowaddSubview:circleChart]; 文章转载自 开源中国社区[https://www.oschina.net]

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码