国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

ios 照相機和相冊的調用

瀏覽:14日期:2022-09-17 13:38:13

一個簡單的功能,上傳照片或者拍照可以用到.

//首先遵循兩個代理 <UIImagePickerControllerDelegate,UINavigationControllerDelegate> //我們創建一個btn和一個imageview,btn用來觸發事件調起照相機和相冊的功能,imageview用來展示選取或者拍攝的圖片. self.view.backgroundColor = [UIColor whiteColor]; UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(100 , 100, 200,50)]; btn.backgroundColor = [UIColor blackColor]; [btn setTitle:@'ChoosePhoto' forState:UIControlStateNormal]; [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn]; _imageview = [[UIImageView alloc]initWithFrame:CGRectMake(200, 200, 100, 100)]; _imageview.backgroundColor = [UIColor lightGrayColor]; _imageview.layer.cornerRadius = CGRectGetHeight(_imageview.bounds)/2; _imageview.clipsToBounds = YES; [self.view addSubview:_imageview]; //btn的點擊事件 - (void)btnClick:(UIButton *)btn{ //創建UIAlertController是為了讓用戶去選擇照片來源,拍照或者相冊. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:0]; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@'從相冊選取' style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {imagePickerController.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;[self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *photoAction = [UIAlertAction actionWithTitle:@'拍照' style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;[self presentViewController:imagePickerController animated:YES completion:^{}]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@'取消' style:(UIAlertActionStyleCancel) handler:^(UIAlertAction *action) { //這里可以不寫代碼 }]; [self presentViewController:alertController animated:YES completion:nil]; //用來判斷來源 Xcode中的模擬器是沒有拍攝功能的,當用模擬器的時候我們不需要把拍照功能加速 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {[alertController addAction:okAction];[alertController addAction:cancelAction];[alertController addAction:photoAction]; } else {[alertController addAction:okAction];[alertController addAction:cancelAction]; }} //這個是選取完照片后要執行的代理方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ [picker dismissViewControllerAnimated:YES completion:^{}]; //選取裁剪后的圖片 UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; /* 此處info 有六個值 * UIImagePickerControllerMediaType; // an NSString UTTypeImage) * UIImagePickerControllerOriginalImage; // a UIImage 原始圖片 * UIImagePickerControllerEditedImage; // a UIImage 裁剪后圖片 * UIImagePickerControllerCropRect; // an NSValue (CGRect) * UIImagePickerControllerMediaURL; // an NSURL * UIImagePickerControllerReferenceURL // an NSURL that references an asset in the AssetsLibrary framework * UIImagePickerControllerMediaMetadata // an NSDictionary containing metadata from a captured photo */ _imageview.image = image;}

標簽: IOS
上一條:淺談iOS的文件操作下一條:iOS繪圖
相關文章:
主站蜘蛛池模板: 免费人成网站在线播放 | 99视频在线免费观看 | 成人黄色在线观看 | 国产日产亚洲系列首页 | 三级大片在线观看 | 抱着cao才爽免费观看 | 欧美色老头gay | 日韩毛片在线免费观看 | 久草在线中文视频 | 尹人香蕉久久99天天拍 | 欧美成年免费a级 | 一级成人黄色片 | 国产一级特黄aaa大片 | 日韩亚洲一区中文字幕 | 亚洲成人看片 | 久久久久久免费精品视频 | 国产精品久久一区 | 国产精品亚洲一区二区三区在线观看 | 久久只有这才是精品99 | 99在线观看视频免费精品9 | 黄色三级理沦片 | 99久久综合国产精品免费 | 日韩免费a级在线观看 | 亚洲成a人在线播放www | 欧美—级v免费大片 | 亚洲在线视频播放 | 一区二区中文字幕亚洲精品 | 成人精品视频在线观看 | 国产的一级毛片完整 | 中文字幕福利片 | 亚洲线精品久久一区二区三区 | 欧美综合在线观看 | 欧美日韩亚洲综合在线一区二区 | 在线国产一区二区 | 免费国产不卡午夜福在线观看 | 欧美三级在线视频 | 亚洲天堂久久精品 | 中国一级淫片aaa毛片毛片 | 91久久精品国产91久久性色也 | 亚洲性综合 | 无内丝袜透明在线播放 |