我的應用程序在info.plist中設置爲僅支持肖像模式。擴展UIImagePicker控制器無助於防止在io6中旋轉
但是,當用戶將屏幕旋轉到橫向時,UIImagePickerController會旋轉。
由於IO6方法shouldAutoRotate不會被調用,我試着像這樣延伸:
@interface NonRotatingUIImagePickerController : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskPortrait;
}
@end
但它並不能幫助。任何想法爲什麼?
而在日誌中我看到上述方法被調用。 UIImagePickerController首先以縱向顯示,當用戶旋轉時 - 它也旋轉,而不是保持縱向。
我設置在這樣的視圖中的圖片選擇器:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self.imagePickerController) {
self.imagePickerController = [[NonRotatingUIImagePickerController alloc] init];
self.imagePickerController.delegate = self;
}
return self;
}
- (void)viewDidAppear:(BOOL)animated{
self.imagePickerController.showsCameraControls = NO;
CGRect imagePickerControllerFrame = CGRectMake(0, topBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - topBar.frame.size.height - bottomBar.frame.size.height);
self.imagePickerController.view.frame = imagePickerControllerFrame;
self.imagePickerController.allowsEditing = YES;
self.imagePickerController.view.clipsToBounds = YES;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera
[self.view.window addSubview:self.imagePickerController.view];
}
你能展示代碼來證明你實際上在使用這個類嗎? – matt
完成。請注意,我添加圖像選擇器作爲子視圖 – Dejell