UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init] ;
[imagePicker setAllowsEditing:YES] ;
[imagePicker setDelegate:self] ;
[imagePicker setMediaTypes:[NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil]] ;
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary] ;
[self presentViewController:imagePicker animated:YES completion:nil] ;
-3
A
回答
1
第1步:添加委託
@interface APPViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
第2步:初始化UIImagePicker上點擊按鈕動作
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
第3步:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
第4步:關閉控制器
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
注意:您發佈的細節描述問題
0
您正在使用的UIImagePickerController作爲變量而不是作爲一個屬性或特性,這意味着將在您的函數結束時被釋放。將您的UIImagePickerController設置爲屬性或屬性,然後該委託將工作。
0
如果您使用的是UIPopoverPresentationController,請確保在呈現imagePicker之前關閉彈出窗口。否則,它不會顯示。
相關問題
- 1. UIImagePickerController不工作
- 2. UIImagePickerController不工作4.0.2
- 3. 的UIImagePickerController allowsEditing = YES不工作
- 4. UIImagePickerController在iOS設備上工作,但不在iOS模擬器上?
- 5. UIImagePickerController相機不工作swift
- 6. 的UIImagePickerController在iOS 6中不能正常工作
- 7. UIImagePickerController允許編輯不工作
- 8. 自定義UIImagePickerController視圖不工作
- 9. UIImagePickerController設置背景圖片,不工作
- 10. iOS UIImagePickerController和ModalViewController
- 11. UIImagePickerController只能工作一次
- 12. 無法獲取UIImagePickerController工作
- 13. 的UIImagePickerController」不包含定義‘DismissModalViewControllerAnimated’Xamrian的iOS
- 14. 的UIImagePickerController iOS中不開放6.0
- 15. iOS 8 Bug與UIImagePickerController圖像作物
- 16. IOS自定義UIImagePickerController
- 17. iOS 6的後面的UIImagePickerController
- 18. 的iOS 5:崩潰的UIImagePickerController
- 19. iOS7的UIImagePickerController allowsEditing無法正常工作
- 20. iOS - onload不工作
- 21. Libgdx IOS不工作?
- 22. IOS isEqualToString不工作
- 23. Adcolony不工作(iOS)
- 24. searchBarSearchButtonClicked不工作IOS
- 25. ccTouchBegan不工作-IOS
- 26. iOS NSPredicate不工作?
- 27. iOS - setIdleTimerDisabled:NO不工作
- 28. audioSessionGetProperty不工作(IOS)
- 29. IOS - performSelector:withObject:afterDelay:不工作
- 30. iOS裝置:和的UIImagePickerController ResignFirstResponder
用適當的格式發佈您的問題。 –
您可以添加輸出控制檯嗎?什麼是錯誤? – thedjnivek