iOS7 打开相机代码
来源:互联网 发布:java安装后怎么启动 编辑:程序博客网 时间:2024/04/29 04:38
废话少说,直接上代码。。。。
#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>@property (weak, nonatomic) UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageView = [[UIImageView alloc] init]; imageView.frame = CGRectMake(100, 100, 100, 100); self.imageView = imageView; [self.view addSubview:imageView]; UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; button.frame = CGRectMake(100, 50, 100, 100); [button addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];}- (void)click{ if ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0) { // 提醒用户在哪里可以设置 AVAuthorizationStatus state = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (state == AVAuthorizationStatusRestricted || state == AVAuthorizationStatusDenied) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"请在iPhone的“设置-隐私-相机”选项中允许XXX访问您的手机相机" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:alertAction]; [self presentViewController:alertController animated:YES completion:nil]; } } UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *pickerController = [[UIImagePickerController alloc] init]; pickerController.delegate = self; pickerController.sourceType = sourceType; [self presentViewController:pickerController animated:YES completion:nil]; } else { // 把UIAlertView, UIActionSheet集成UIAlertController UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"无法启动照相机" preferredStyle:UIAlertControllerStyleAlert];// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"无法启动照相机" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *alertAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; [alertController addAction:alertAction]; [self presentViewController:alertController animated:YES completion:nil]; /** UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"无法启动照相机" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil]; [alertView show]; */ }}#pragma mark - 最新- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ [picker dismissViewControllerAnimated:YES completion:nil]; self.imageView.image = info[UIImagePickerControllerOriginalImage];}#pragma mark - NS_DEPRECATED_IOS(2_0, 3_0)过期- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary<NSString *,id> *)editingInfo{ [picker dismissViewControllerAnimated:YES completion:nil]; self.imageView.image = image;}- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { [self dismissViewControllerAnimated:YES completion:nil];}
0 0
- iOS7 打开相机代码
- 一行代码打开相册/相机
- 打开相册相机上传照片代码
- iOS7相机隐私判断
- ios7打开相册和相机时状态栏不隐藏的问题
- 调用系统相机以及 打开相册的代码
- iOS7 打开http使用方法
- 打开相机、相册
- 打开相机的闪光灯
- iOS 打开相机、相册
- matlab打开相机
- QObject::moveToThread() 打开相机
- Android打开相机
- android打开相机拍照
- Android 打开相机,相册
- IOS7判断程序是否可用相机
- 自定义相机,用于默认打开前置相机
- 用户权限打开引导 (相机)
- pathon爬虫(三)之post请求
- GitHub 优秀源码记录
- Address localhost:1099 is already in use 8080端口被占用
- python常见的模块
- LeetCode 129. Sum Root to Leaf Numbers 解题报告
- iOS7 打开相机代码
- 关于使用 git 上传代码至 github 的方法
- JSTL的简单使用
- JavaCompiler编译的时候有时会返回NULL
- 算法-Nim 游戏-(拿石头游戏)
- {dede:global.cfg_templets_skin/}是什么意思
- tomcat在eclipse中起动成功,主页却打不开
- linux 版本source insight
- UITableView的优化