2011-05-31 131 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

相關問題