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

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

ios 照相機和相冊的調用

瀏覽:44日期: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繪圖
相關文章:
主站蜘蛛池模板: 国产香港特级一级毛片 | 成人人免费夜夜视频观看 | 热久久伊人 | 国产一级做a爰片在线 | 99久久免费国产精精品 | 久久影视一区 | 国产精品视频免费播放 | 欧美成 人h版在线观看 | 国产成人综合一区精品 | 国产成人精品女人不卡在线 | 日韩麻豆 | re久久| 欧美成a | 国产三香港三韩国三级不卡 | 欧美日韩一区二区三区四区在线观看 | 草草影院ccyy免费看片 | 欧美一级特黄特黄做受 | 精品国产一区二区三区国产馆 | 日本免费在线观看视频 | 欧美成人26uuu欧美毛片 | 美女黄页在线观看 | 欧美成人午夜不卡在线视频 | 91九九| 久久在现| 成人免费毛片视频 | 精品久久久久久中文字幕一区 | 国产一起色一起爱 | 亚洲黄色在线视频 | 91精品视频播放 | 国产精品特级毛片一区二区三区 | 久久精品国产亚洲欧美 | 国产欧美日韩不卡在线播放在线 | 国产精品手机视频一区二区 | 日本综合久久 | 美女和男人免费网站视频 | 久久91视频 | 午夜精品影院 | 国产一区二区在线观看免费 | 免费看欧美一级片 | 在线亚洲观看 | 国产色a|