2011-06-21 164 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”中出现此错误。我尝试使用自动调整屏幕来改变实时屏幕的方向,但这并没有帮助。 –