我正在嘗試瀏覽圖像並使用UIImagePickerController
在imageview
中顯示。基本上我用來瀏覽圖像的視圖基於navigationController
。導航視圖控制器中的IOS圖像選取器
但是,在選擇圖像並回來查看後,使用下面的代碼,我可以看到視圖閃爍到左側,圖像未在圖像視圖中顯示。
實際上整個源代碼都退出很長時間,這就是爲什麼我只發佈圖像選擇器部分。如果需要,我可以發佈更多的代碼。
RegistrationFormViewController.h
@interface RegistrationFormViewController : ViewController
<UIImagePickerControllerDelegate,UINavigationControllerDelegate,CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
UIImagePickerController *imagePickerController;
}
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (weak, nonatomic) IBOutlet UIImageView *imageUser;
- (IBAction)registerBt:(id)sender;
RegistrationFormViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
_barButtonBack.target = self.revealViewController;
_barButtonBack.action = @selector(revealToggle:);
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[self.imageUser setUserInteractionEnabled:YES];
[self.imageUser addGestureRecognizer:singleTap];
}
-(void)tapDetected{
NSLog(@"single Tap on imageview");
imagePickerController = [[UIImagePickerController alloc]init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
#pragma mark - ImagePickerController Delegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
// Dismiss the image selection, hide the picker and
//show the image view with the picked image
[picker dismissViewControllerAnimated:YES completion:nil];
[self.imageUser setImage:image];
self.imageUser.contentMode = UIViewContentModeScaleAspectFill;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
爲什麼你在'didFinishPickingImage'回調更新'self.imageUser.contentMode'? – ozgur
其實我對ios很陌生,做了導致問題的原因,我已經評論過這個部分,但其行爲仍然是一樣的。 – Haris
至少先更新內容模式,然後設置圖像,最後關閉選取器。 – ozgur