复制相机应用旋转以使IOS 6 iPhone风景优美 [英] Replicate camera app rotation to landscape IOS 6 iPhone

查看:80
本文介绍了复制相机应用旋转以使IOS 6 iPhone风景优美的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制相同的旋转,当方向更改为横向时,可以在相机应用程序中看到该旋转.不幸的是我没有运气.我需要使用UIImagePickerController为自定义的cameraOverlayView进行设置.

Hi I am trying to replicate the same rotation which can be seen in the camera app when orientation is shifted to landscape. Unfortunately I've had no luck. I need to set this up for the custom cameraOverlayView with UIImagePickerController.

从这张画像开始(B是UIButtons)

From this portrait (B are UIButtons)

|-----------|
|           |
|           |
|           |
|           |
|           |    
|           |
| B   B   B |
|-----------|

到这个风景

|----------------|
|              B |
|                |
|              B |
|                |
|              B |
|----------------|

换句话说,我希望按钮能贴在原始人像底部并在其中心旋转.我正在使用情节提要,并且启用了自动布局.任何帮助,我们将不胜感激.

In other words I would like the buttons to stick to the original portrait bottom and rotate on their centres. I am using Storyboards and Autolayout is enabled. Any help is greatly appreciated.

推荐答案

好的,所以我设法解决了这个问题.需要注意的一点是,UIImagePickerController类仅根据Apple 文档.

OK, so I've managed to sort this out. A thing to note is the UIImagePickerController class supports portrait mode only as per Apple documentation.

要捕获旋转,此处的willRotateToInterfaceOrientation是无用的,因此必须使用通知.同样,在运行时设置自动布局约束也并非可行.

To capture the rotation the willRotateToInterfaceOrientation is useless here, so you have to use notificatons. Also setting autolayout contraints at runtime is not the way to go.

在AppDelegate didFinishLaunchingWithOptions中,您需要启用轮播通知:

In the AppDelegate didFinishLaunchingWithOptions you need to enabled rotation notifications:

// send notification on rotation
[[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];

在cameraOverlayView UIViewControllerviewDidLoad方法中,添加以下内容:

In viewDidLoad method of the cameraOverlayView UIViewController add the following:

//add observer for the rotation notification
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

最后将orientationChanged:方法添加到cameraOverlay UIViewController

Finally add the orientationChanged: method to the cameraOverlay UIViewController

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    double rotation = 0;

    switch (orientation) {
        case UIDeviceOrientationPortrait:
            rotation = 0;
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            rotation = M_PI;
            break;
        case UIDeviceOrientationLandscapeLeft:
            rotation = M_PI_2;
            break;
        case UIDeviceOrientationLandscapeRight:
            rotation = -M_PI_2;
            break;
        case UIDeviceOrientationFaceDown:
        case UIDeviceOrientationFaceUp:
        case UIDeviceOrientationUnknown:
        default:
            return;
    }
    CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
    [UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        self.btnCancel.transform = transform;
        self.btnSnap.transform = transform;     
    }completion:nil];
}

上面的代码将旋转变换应用于我在这种情况下使用的btnCancel和btnSnap的2个UIButton上.旋转设备时,这会为您提供相机"应用程序效果. 我仍然在控制台<Error>: CGAffineTransformInvert: singular matrix.中收到警告,不确定为什么会发生这种情况,但这与相机视图有关.

The above code applies the rotation transform on the 2 UIButtons I am using in this case btnCancel and btnSnap. This gives you the Camera app effect when rotating the device. I am still getting a Warning in the console <Error>: CGAffineTransformInvert: singular matrix. not sure why this is happening but it is something to do with the camera view.

希望以上帮助.

这篇关于复制相机应用旋转以使IOS 6 iPhone风景优美的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆