【发布时间】:2013-01-21 18:21:36
【问题描述】:
我的应用在 info.plist 中设置为仅支持纵向模式。
但是,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];
}
【问题讨论】:
-
你能用代码证明你确实在使用这个类吗?
-
完成。请注意,我将图像选择器添加为子视图
标签: objective-c cocoa-touch ios6 uiimagepickercontroller