iPad 相机覆盖方向问题

发布于 2024-11-16 12:28:24 字数 1557 浏览 2 评论 0原文

我正在为 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];
        }
    }
}

谁能告诉我如何检测相机覆盖范围内设备的旋转?

非常感谢

I am developing an app for iPad2 which allows user to take photos. I am going to use custom overlay for image picker. But this overlay view does not detect the orientation of the device.

I have tried with
didRotateFromInterfaceOrientation and willAnimateRotationToInterfaceOrientation. But non of them are working. This is how I am creating overlay.

@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];
        }
    }
}

Can anyone please tell me how can I detect the rotation of the device within camera overlay?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌梦深 2024-11-23 12:28:24

我自己解决了上述问题。
上面的函数已经像这样重新创建了。

-(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

感谢您查看此内容。

I have solove above issue by myself.
The above function has been recreated like this.

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

Then I have use navigation controller delegate. Within this function I could capture the device orientation and solved my issues.

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

Thanks for viewing this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文