2015-10-22 53 views
0

我有點奇怪的情況。我有一個照片應用程序,可根據加載的圖像的尺寸自動設置應用程序的方向。我使用下面的代碼。UIImagePicker跳回到肖像選擇

- (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,而不是選擇器現在處於橫向模式,它會跳回到縱向,看起來很醜。

有沒有更好的方法根據圖像設置設備方向或解決上述問題?

回答

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]; 

}