2013-04-23 61 views
1

我想禁用UIImagePickerView的自动旋转。所以我使用了下面的代码:禁用UIImagePickerController的自动旋转

UIDevice *currentDevice = [UIDevice currentDevice]; 


     [parentViewController presentViewController:imagePicker animated:YES completion:nil]; 

     while ([currentDevice isGeneratingDeviceOrientationNotifications]) 
      [currentDevice endGeneratingDeviceOrientationNotifications]; 

它禁用ImagePickerView,但它也禁用了旋转根视图。但我想在我的根视图控制器中的自动旋转功能(或者我只想在我的ImagePickerController中禁用自动旋转功能)。为了澄清,在禁用UIImagePickerController自动旋转之前,自动旋转在我的根视图中处于活动状态。

最新通报&答::

我找到了答案。写下面的代码启用自动旋转:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

如果您有任何图像处理(其实我有),调用此方法完成所有图像处理任务之后。在我的情况下,我在图像处理之前调用它,并且它没有启用方向。

回答

-1

这就是我的做法。 UIImageViewController是一个UIViewController,它有一个名为 - (BOOL)shouldAutorotate的方法;

我们可以做的是创建一个UIImageViewController的子类并重写shouldAutorotate方法。比方说,我们的子类的名字是MyImageViewController。

然后MyImageViewController.h看起来喜欢 -

#import <UIKit/UIKit.h> 

@interface MyImageViewController : UIImagePickerController 

@end 

而且MyImageViewController.m文件应该是喜欢 -

#import "MyImagePickerViewController.h" 

@interface MyImagePickerViewController() 

@end 

@implementation MyImagePickerViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
} 

-(BOOL)shouldAutorotate{ 
    return NO; 
} 
@end 

现在我们是好去!而不是创造的UIImagePickerViewController,我们可以在parentViewController创建MyImagePickerViewController喜欢 -

MyImagePickerViewController *imagePicker = [[MyImagePickerViewController alloc] init]; 
[parentViewController presentViewController:imagePicker animated:YES completion:nil]; 

为您的shouldAutoRotate设置为NO它不会自动旋转;

-1

试试这个:

@interface UIImagePickerController(addition) 

@end 
@implementation UIImagePickerController(addition) 

-(BOOL)shouldAutorotate{ 
    return NO; 
} 

@end