2011-06-21 273 views
1

我正在開發一款允許用戶拍照的iPad2應用程序。我將爲圖像選擇器使用自定義疊加層。但是,此疊加視圖不檢測設備的方向。iPad攝像頭覆蓋方向問題

我試過 didRotateFromInterfaceOrientationwillAnimateRotationToInterfaceOrientation。但他們中沒有人在工作。這是我創建覆蓋圖的方式。

@interface CameraOverlayController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 


-(void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType 
{ 
    self.picker.sourceType = sourceType; 

    if (sourceType == UIImagePickerControllerSourceTypeCamera) 
    {   
     self.picker.showsCameraControls = NO;   

     if ([[self.picker.cameraOverlayView subviews] count] == 0) 
     { 
      CGRect overlayViewFrame = self.picker.cameraOverlayView.frame; 

      if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) { 
       NSLog(@"Initially Landscape and height : %f" , CGRectGetHeight(overlayViewFrame)); 
      } 
      if (UIDeviceOrientationIsPortrait(self.interfaceOrientation)) { 
       NSLog(@"Initially Portrait and height : %f", CGRectGetHeight(overlayViewFrame)); 
      } 
      self.view.backgroundColor = [UIColor clearColor]; 

      CGRect newFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - self.view.frame.size.height - 10.0, CGRectGetWidth(overlayViewFrame), self.view.frame.size.height + 10.0); 

      self.view.frame = newFrame; 
      [self.picker.cameraOverlayView addSubview:self.view]; 
     } 
    } 
} 

任何人都可以請告訴我如何檢測相機覆蓋內設備的旋轉?

非常感謝

回答

-1

我自己解決了上述問題。 上述功能已被重新創建。

-(void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType 
{ 
    self.picker.sourceType = sourceType; 
    if (sourceType == UIImagePickerControllerSourceTypeCamera) 
    { 
     self.picker.showsCameraControls = NO;     
    } 
} 

然後我使用導航控制器委託。在此功能中,我可以捕獲設備方向並解決我的問題。

-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 

感謝您瀏覽此項。

+0

你好你能解釋一下嗎?你能告訴我你是如何實現willShowViewController的嗎?謝謝 –

+1

這willShowViewController是一個導航控制器委託。在此方法內實現所有UI(navigationController工具欄,按鈕等),並將其作爲子視圖添加到viewController。我希望這能幫到您。 – Chinthaka

+0

@Chinthaka:嗨...我已經創建了一個自定義相機,並且現場屏幕可以在肖像模式下正常加載。但是當我將其更改爲橫向模式時,在控制檯「CGAffineTransformInvert:singular matrix」中出現此錯誤。我嘗試使用自動調整屏幕來改變實時屏幕的方向,但這並沒有幫助。 –