将相机应用程序旋转复制到横向IOS 6 iPhone

前端之家收集整理的这篇文章主要介绍了将相机应用程序旋转复制到横向IOS 6 iPhone前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨我正在尝试复制相同的旋转,当方向转移到横向时,可以在相机应用程序中看到.不幸的是我没有运气.我需要使用UI ImagePickerController为自定义cameraOverlayView设置它.

从这幅肖像(B是UIButtons)

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

到了这个景观

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

换句话说,我希望按钮能够粘在原始肖像底部并在其中心旋转.我正在使用Storyboard并启用了Autolayout.任何帮助是极大的赞赏.

解决方法

好的,所以我设法解决了这个问题.需要注意的是UIImagePickerController类仅支持纵向模式,如Apple documentation所示.

要捕获旋转,willRotateToInterfaceOrientation在这里是无用的,因此您必须使用通知.在运行时设置自动布局约束也不是可行的方法.

在AppDelegate didFinishLaunchingWithOptions中,您需要启用旋转通知

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

在cameraOverlayView UIViewController的viewDidLoad方法添加以下内容

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

最后将orientationChanged:方法添加到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];
}

上面的代码在我使用的2个UIButtons上应用了旋转变换btnCancel和btnSnap.这样可以在旋转设备时为您提供相机应用效果.
我仍然在控制台中收到警告<错误>:CGAffineTransformInvert:奇异矩阵.不知道为什么会发生这种情况,但这与摄像机视图有关.

希望以上有所帮助.

原文链接:https://www.f2er.com/iOS/332706.html

猜你在找的iOS相关文章