UIImagePicker选中后跳回纵向

时间:2015-10-22 10:54:19

标签: ios objective-c uiimagepickercontroller

我有点奇怪的情况。我有一个照片应用程序,可根据加载的图像尺寸自动设置应用方向。我使用以下代码。

- (BOOL)prefersStatusBarHidden {
return YES;
}

- (BOOL) shouldAutorotate {
return NO;
}

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return NO;
}

- (IBAction)setRotation {

if(imageOriginal.size.height > imageOriginal.size.width){

    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

}else {

    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];

}

}

问题在于我可以说我将肖像图像加载到UIImagePicker处于纵向模式的应用程序中。我现在选择一个风景图像并再次选择UIImagePicker,而不是现在处于横向模式的选择器,它会跳回到肖像并且看起来非常难看。

是否有更好的方法根据图像设置设备方向或解决上述问题?

1 个答案:

答案 0 :(得分:0)

找到更改以下代码所需的解决方案,以确保UIImagePicker处于上下文中。

- (IBAction)loadImage:(id)sender {

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
-- > imagePicker.modalPresentationStyle = UIModalPresentationCurrentContext;
//imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:NO completion:nil];

}