iPad相机叠加方向问题

时间:2011-06-21 17:15:03

标签: ipad camera orientation overlay uiimagepickercontroller

我正在为iPad2开发一款应用程序,允许用户拍照。我将使用自定义叠加图像选择器。但是此叠加视图不会检测设备的方向。

我试过了 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 个答案:

答案 0 :(得分:-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

感谢您查看此内容。