亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

ios 照相機和相冊的調用

瀏覽:41日期: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繪圖
相關文章:
主站蜘蛛池模板: 亚洲国产成人久久笫一页 | 国产精品秒播无毒不卡 | 性做久久久久久网站 | 欧美日韩国产片 | 女人被躁的视频在线观看 | 日本欧美国产精品第一页久久 | 色噜噜五月综合激情久久爱 | 日韩一区二区久久久久久 | 日韩久久中文字幕 | 狠狠做久久深爱婷婷97动漫 | 国产最新自拍 | 鲁大师7视频在线观看 | 国产伦精品一区二区免费 | 免费一区二区三区四区五区 | 美国激情ap毛片 | 亚洲视频国产视频 | 欧美日韩一区二区三区在线 | 免费网站www7788con | 久久99精品久久久久子伦小说 | 国产精品亚洲午夜一区二区三区 | 国产a级三级三级三级中国 国产a级午夜毛片 | 国内国内在线精品视频 | 久青草视频免费视频播放线路1 | 日本3级网站 | 亚洲欧美日韩国产一区二区三区精品 | 九九爱精品 | 91久久夜色精品国产九色 | 亚洲欧美国产精品第1页 | 国产乱码精品一区二区 | 麻豆精品国产免费观看 | 青青热久免费精品视频在线观看 | 亚洲国产精品免费视频 | 国产一区二区在线视频播放 | 黄网址大全免费观看免费 | 日韩毛片在线看 | 制服丝袜中文字幕在线观看 | 日本人一级毛片免费完整视频 | 欧美日韩精品一区二区三区视频 | 青青草无限次破解版污 | 美女国产福利视频 | 精品国产第一国产综合精品 |