日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IOS开发之小实例--UIImagePickerController

發布時間:2023/12/19 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IOS开发之小实例--UIImagePickerController 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

摘自:http://www.cnblogs.com/goodboy-heyang/p/5403947.html

前言:本篇博文是本人閱讀國外的IOS Programming Tutorial的一篇入門文章的學習過程總結,難度不大,因為是入門。主要是入門UIImagePickerController這個控制器,那么這個 控制器是干嘛的呢?就是調用設備攝像機功能用的。到后面可能需要您在真機上測試,因為iPhone模擬器無法支持攝像機功能,運行測試會崩潰的哦。

?

網址:http://www.appcoda.com/ios-programming-camera-iphone-app/

1、首先簡單的創建一個工程,然后在storyboard和對應的.m文件中添加相關的代碼,這個簡明教程沒有使用自動布局,不多說,看圖識字:

?

2、下面是這個ViewController.m的完整實現:

#import "ViewController.h"@interface ViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>@property (strong, nonatomic) IBOutlet UIImageView *imageView;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// 這段代碼會自動判斷當前設備是否有攝像機功能,如果沒有,會彈窗提示if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"message:@"Device has no camera"delegate:nilcancelButtonTitle:@"OK"otherButtonTitles: nil];[myAlertView show];} } - (IBAction)takePhotot:(UIButton *)sender {// 創建UIImagePickerController控制器對象UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;picker.allowsEditing = YES;picker.sourceType = UIImagePickerControllerSourceTypeCamera;[self presentViewController:picker animated:YES completion:nil]; } - (IBAction)selectPhoto:(UIButton *)sender {// 創建UIImagePickerController控制器對象UIImagePickerController *picker = [[UIImagePickerController alloc] init];picker.delegate = self;picker.allowsEditing = YES;picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;[self presentViewController:picker animated:YES completion:nil]; } #pragma mark - 代理方法 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{UIImage* chosenImage = info[UIImagePickerControllerEditedImage];self.imageView.image = chosenImage;[picker dismissViewControllerAnimated:YES completion:nil]; } -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{[picker dismissViewControllerAnimated:YES completion:nil]; }@end

?

轉載于:https://www.cnblogs.com/Lucky-056150/p/5404271.html

總結

以上是生活随笔為你收集整理的IOS开发之小实例--UIImagePickerController的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。