我有一个使用UIImagePicker上的叠加层的应用程序。 我做到了,所以有两个故事板,一个用于iPhone,一个用于iPad。在我的info.plist中,我列出了这两种设备仅使用横向视图(左右)。在我的ViewController.m中,我有
-(BOOL)shouldAutorotate
{ return NO;
}
当应用启动时,两个设备都可以通过不旋转来正常运行。
但是,当我打开带有overlayView的UIImagePicker来创建增强现实时,iPhone不会旋转,而iPad会旋转。我不想让iPad旋转,但不知道如何旋转。
这是我用来创建叠加视图和其上另一个视图的代码。
picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera ;
picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
CGSize screenSize = [[UIScreen mainScreen] bounds].size; // 320 x 568
float scale = screenSize.width / screenSize.height*5/3; // screen height divided by the pickerController height ... or: 568 / ( 320*4/3 )
CGAffineTransform translate=CGAffineTransformMakeTranslation(0,(screenSize.height - screenSize.width*4/3)*0.5);
CGAffineTransform fullScreen=CGAffineTransformMakeScale(scale, scale);
picker.cameraViewTransform =CGAffineTransformConcat(fullScreen, translate);
OverlayView = [[OverlayView alloc] initWithFrame:CGRectMake(-20, -256, 360,1024)];
self.OverlayView.opaque = NO;
self.OverlayView.backgroundColor = [UIColor clearColor];
realView = [[UIView alloc] initWithFrame:CGRectMake(-20, -256, 360,1024)];
[realView addSubview:OverlayView];
picker.cameraOverlayView = realView;
[self presentViewController: picker animated:YES completion:NULL]; //could this be the problem?
我使用此方法使图像视图适合iPhone屏幕的正确大小。这就是阻止iPhone旋转而不是iPad旋转的原因。关于为什么发生这种情况以及如何阻止它的任何想法。