OC - 相机管理

OC - 相机管理 首页 / iOS入门教程 / OC - 相机管理

相机是移动设备中的常见功能之一。无涯教程可以用相机拍照并在无涯教程的应用程序中使用它,这也非常简单。

相机管理步骤

步骤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.comhttps://www.learnfk.com/ios/ios-camera-management.html

来源:LearnFk无涯教程网

iOS Tutorial

拍照后,无涯教程可以编辑图片,即如下所示移动和缩放-

iOS Tutorial

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

Kafka核心技术与实战 -〔胡夕〕

高并发系统设计40问 -〔唐扬〕

分布式系统案例课 -〔杨波〕

Selenium自动化测试实战 -〔郭宏志〕

程序员的个人财富课 -〔王喆〕

零基础实战机器学习 -〔黄佳〕

玩转Vue 3全家桶 -〔大圣〕

React Native 新架构实战课 -〔蒋宏伟〕

深入拆解消息队列47讲 -〔许文强〕

好记忆不如烂笔头。留下您的足迹吧 :)