2011-05-31 84 views
2

此要求适用于iPad的 我有一个UIView在启动视频录制时用作相机覆盖视图。它在UIImagePickerController中设置如下。iPad:仅将UIView方向锁定为横向模式

[self presentModalViewController:pickerController animated:NO]; 
pickerController.cameraOverlayView =myOwnOverlay; 

这是我的要求,我必须在调用摄像机进行视频录制时在UIImagePickerController中提供自己的覆盖图。 我想锁定自己的相机覆盖UIView进入景观模式,以便允许用户只能在横向模式下录制视频,而不是在肖像模式下,这也是我的项目需求。 我知道有关用于UIViewController的shouldAutorotateToInterfaceOrientation。我用“[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];”它,它锁定风景模式,当我启动这个相机自己的覆盖UIView,但是当我旋转设备,UIView也旋转到肖像。我根本不需要肖像模式。我试图像下面这样处理这个问题,但它不适用于UIView。然后我看到这是可能的UIviewController,但不是在UIView。但是我必须让UIView进行这个相机发射操作。

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

return (interfaceOrientation==UIInterfaceOrientationLandscapeRight || interfaceOrientation==UIInterfaceOrientationLandscapeLeft); 
} 

请指教我如何为我的UIView提供方向锁解决方案?

谢谢!

+0

有人请吗? – Getsy 2011-06-01 18:56:15

回答

1

怀疑是否允许来自APPLE,但如果您希望UIImagePickerController以横向方向启动(并保持),请使用以下代码。

//Initialize picker 

UIImagePickerController * picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 


//set Device to Landscape. This will give you a warning. I ignored it. 
//warning: 'UIDevice' may not respond to '-setOrientation:' 


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 

//Set Notifications so that when user rotates phone, the orientation is reset to landscape. 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

//Refer to the method didRotate: 
[[NSNotificationCenter defaultCenter] addObserver:self 
       selector:@selector(didRotate:) 
       name:@"UIDeviceOrientationDidChangeNotification" object:nil]; 

//Set the picker source as the camera 
picker.sourceType = UIImagePickerControllerSourceTypeCamera; 

//Bring in the picker view 
[self presentModalViewController:picker animated:YES]; 

的方法didRotate:

- (void) didRotate:(NSNotification *)notification 

{ 
     //Maintain the camera in Landscape orientation 
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 

} 

信用此代码属于UIImagePickerController in Landscape

+0

但有时应用程序在didRotate方法中崩溃 – iBhavik 2012-07-31 13:25:21

1

试试这个:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

{ 
    BOOL isLandscapeRight = (UIInterfaceOrientationLandscapeRight == interfaceOrientation); 
    return isLandscapeRight; 
} 

而且还可以设置您的应用程序info.plist中的接口定位到风景(右侧主页按钮)

1

这里有一个简单的解决方案 在info.plist文件中编辑入口支持的接口方向ipad。

enter image description here

相关问题