亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

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

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

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

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

//首先遵循兩個代理 <UIImagePickerControllerDelegate,UINavigationControllerDelegate> //我們創(chuàng)建一個btn和一個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)用模擬器的時候我們不需要把拍照功能加速 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {[alertController addAction:okAction];[alertController addAction:cancelAction];[alertController addAction:photoAction]; } else {[alertController addAction:okAction];[alertController addAction:cancelAction]; }} //這個是選取完照片后要執(zhí)行的代理方法 - (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;}

標(biāo)簽: IOS
上一條:淺談iOS的文件操作下一條:iOS繪圖
相關(guān)文章:
主站蜘蛛池模板: 国产边打电话边做对白刺激 | 国产高清在线精品 | 亚洲欧洲小视频 | 欧美人牲囗毛片 | 亚洲精品一区二区三区www | 一级毛片一级毛片一级毛片 | 欧美成人另类69 | 国产成人高清亚洲一区久久 | 国产三级精品三级国产 | 在线播放性xxx欧美 在线播放亚洲视频 | 飘花国产午夜精品不卡 | 毛片在线高清免费观看 | 国产精品亚洲精品日韩已满 | 国产精品久久久久久久久免费观看 | 午夜欧美精品久久久久久久久 | 国产精品麻豆一区二区三区v视界 | 国产午夜a理论毛片在线影院 | 99精品久久久久久 | 日韩欧美在线观看视频一区二区 | 成人男女网18免费0 成人男女网18免费看 | 午夜毛片免费观看视频 | 亚洲国产cao | 97超频国产在线公开免费视频 | 一区视频在线 | 免费日韩在线视频 | 亚洲成色在线 | 亚洲欧美日韩久久精品第一区 | 国产91精品久久久久久久 | 久久91综合国产91久久精品 | 欧美天堂| 国产一级内谢a级高清毛片 国产一级片毛片 | 国产区精品在线 | 成人免费夜片在线观看 | 亚洲美女自拍视频 | 亚洲欧美视频网站 | 久久精品久久精品 | 一级大黄美女免费播放 | 亚洲久久久久 | 亚洲国产午夜看片 | 九草在线观看 | 久草在线视频中文 |