相机是移动设备中的常见功能之一。无涯教程可以用相机拍照并在无涯教程的应用程序中使用它,这也非常简单。
相机管理步骤
步骤1 - 创建一个简单的基于视图的应用程序。
步骤2 - 在 ViewController.xib 中添加按钮并为该按钮创建IBAction。
步骤3 - 添加图像视图并创建IBOutlet,将其命名为imageView。
步骤4 - 如下更新 ViewController.h -
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIImagePickerControllerDelegate> { UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; } - (IBAction)showCamera:(id)sender; @end
步骤5 - 如下更新 ViewController.m -
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; //Dispose of any resources that can be recreated. } - (IBAction)showCamera:(id)sender { imagePicker.allowsEditing=YES; if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera; } else { imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary; } [self presentModalViewController:imagePicker animated:YES]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage]; if (image == nil) { image=[info objectForKey:UIImagePickerControllerOriginalImage]; } imageView.image=image; } -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissModalViewControllerAnimated:YES]; } @end
当无涯教程运行该应用程序并单击"显示摄像机"按钮时,将获得以下输出-
拍照后,无涯教程可以编辑图片,即如下所示移动和缩放-
参考链接
https://www.learnfk.com/ios/ios-camera-management.html
标签:教程,ViewController,image,OC,无涯,imagePicker,步骤 From: https://blog.51cto.com/u_14033984/7685008