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

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

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

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

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

//首先遵循兩個(gè)代理 <UIImagePickerControllerDelegate,UINavigationControllerDelegate> //我們創(chuàng)建一個(gè)btn和一個(gè)imageview,btn用來觸發(fā)事件調(diào)起照相機(jī)和相冊的功能,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的點(diǎn)擊事件 - (void)btnClick:(UIButton *)btn{ //創(chuàng)建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中的模擬器是沒有拍攝功能的,當(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)文章:
主站蜘蛛池模板: 国产精品久久久久久久专区 | 欧美一级三级 | 俄罗斯一级成人毛片 | 国产欧美视频一区二区三区 | 中文字幕一区在线观看 | 久久久久久久久久久久久久久久久久 | 日韩加勒比 | 国产高清在线精品二区一 | 亚洲精品一区二区三区在 | 欧美成人看片黄a免费 | 美女黄色毛片免费看 | 日韩久久中文字幕 | 久久99精品久久久久久h | 久久精品国产欧美 | 亚洲欧美色视频 | 国内精品久久久久久影院老狼 | 精品欧美高清一区二区免费 | 午夜精品网 | 日本精品久久久久中文字幕 1 | 成人在线高清 | 亚洲欧美日韩高清综合678 | 欧美精品成人一区二区视频一 | 亚洲成人视 | 国产一级在线观看视频 | 国内精品免费一区二区观看 | 免费一区二区三区久久 | 2020精品极品国产色在线观看 | 亚洲精品aaa | 成人免费看 | 国产精品观看在线亚洲人成网 | 国产精品免费看久久久香蕉 | 国产激情一区二区三区 | 真实一级一级一片免费视频 | 久草新在线观看 | 俄罗斯一级黄色片 | 国产在线爱做人成小视频 | 国产成人综合一区精品 | 亚洲影院中文字幕 | 免费播放aa在线视频成人 | 性色aⅴ在线观看swag | 欧美日韩国产亚洲一区二区 |