当设备旋转iOS 7时,UIImagePickerController会旋转

时间:2013-09-21 11:36:13

标签: ios

我有一个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];

代码不起作用控制器仍然旋转。为什么呢?

1 个答案:

答案 0 :(得分:1)

最简单的解决方案 - 在项目文件中允许纵向模式。

作为第二种解决方案 - 尝试将以下代码添加到appdelegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationPortrait;
}
相关问题