av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

ios 照相機(jī)和相冊(cè)的調(diào)用

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

一個(gè)簡(jiǎn)單的功能,上傳照片或者拍照可以用到.

//首先遵循兩個(gè)代理 <UIImagePickerControllerDelegate,UINavigationControllerDelegate> //我們創(chuàng)建一個(gè)btn和一個(gè)imageview,btn用來(lái)觸發(fā)事件調(diào)起照相機(jī)和相冊(cè)的功能,imageview用來(lái)展示選取或者拍攝的圖片. 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的點(diǎn)擊事件 - (void)btnClick:(UIButton *)btn{ //創(chuàng)建UIAlertController是為了讓用戶(hù)去選擇照片來(lái)源,拍照或者相冊(cè). UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:0]; UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.delegate = self; imagePickerController.allowsEditing = YES; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@'從相冊(cè)選取' 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) { //這里可以不寫(xiě)代碼 }]; [self presentViewController:alertController animated:YES completion:nil]; //用來(lái)判斷來(lái)源 Xcode中的模擬器是沒(méi)有拍攝功能的,當(dāng)用模擬器的時(shí)候我們不需要把拍照功能加速 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {[alertController addAction:okAction];[alertController addAction:cancelAction];[alertController addAction:photoAction]; } else {[alertController addAction:okAction];[alertController addAction:cancelAction]; }} //這個(gè)是選取完照片后要執(zhí)行的代理方法 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{ [picker dismissViewControllerAnimated:YES completion:^{}]; //選取裁剪后的圖片 UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; /* 此處info 有六個(gè)值 * 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;}

標(biāo)簽: IOS
上一條:淺談iOS的文件操作下一條:iOS繪圖
相關(guān)文章:
主站蜘蛛池模板: 精品国产一区二区三区久久 | 久久久久网站 | 成人精品国产免费网站 | 一级国产精品一级国产精品片 | 国产日韩欧美另类 | 久久精品无码一区二区三区 | 成人在线中文字幕 | 91久久久久久久久久久 | 每日在线更新av | 精品欧美久久 | 日韩精品一区二区三区 | 中文日韩在线视频 | 日韩一区二区在线视频 | 高清免费在线 | 国产成人免费观看 | 日韩综合在线 | 99色视频| 日韩精品久久一区二区三区 | 国内精品视频免费观看 | 91精品国产一区二区三区 | 成人免费激情视频 | 黑人巨大精品欧美一区二区免费 | 国产 亚洲 网红 主播 | 成人午夜网 | 亚洲日本中文字幕在线 | 中文字幕av亚洲精品一部二部 | 欧美黑人体内she精在线观看 | 欧美一级网站 | 99精品免费 | 国产精品久久久久无码av | 欧美一级www片免费观看 | 亚洲国产aⅴ成人精品无吗 国产精品永久在线观看 | 毛片一级片 | 在线观看的av | 国产在线观看免费 | 亚洲天堂二区 | 国产一区二区在线看 | 欧美日韩在线观看一区 | 亚洲国产精品久久久 | 日韩一区中文字幕 | 久久久久久高潮国产精品视 |