我有一个 UIImagePickerController,我希望它的方向始终保持在纵向模式。该应用程序本身设置为纵向模式,但 UIImagePickerController 改变了方向。我用代码创建了一个自定义 UIImagePickerController:
#import "ViewControllerImage.h"
@interface ViewControllerImage ()
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end
@implementation ViewControllerImage
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
我以这种方式呈现:
ViewControllerImage *picker = [[ViewControllerImage alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
代码不工作 Controller 仍然旋转。为什么?
最佳答案
最简单的解决方案 - 在项目文件中允许纵向模式。
作为第二种解决方案 - 尝试将以下代码添加到您的 appdelegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationPortrait;
}
关于ios - UIImagePickerController 在设备旋转时旋转 iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932095/