复制相机应用程序的旋转,以横向IOS 6 iPhone

嗨,我试图复制相同的旋转,可以看到相机应用程序时,方向转移到风景。 不幸的是我没有运气。 我需要设置为UIImagePickerController自定义cameraOverlayView。

从这张肖像(B是UIButtons)

|-----------| | | | | | | | | | | | | | BBB | |-----------| 

到这个景观

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

换句话说,我想button坚持原来的肖像底部,并在其中心旋转。 我正在使用故事板,并启用Autolayout。 任何帮助是极大的赞赏。

好的,所以我设法解决了这个问题。 需要注意的是,UIImagePickerController类仅支持按照Apple 文档的纵向模式。

为了捕获旋转, willRotateToInterfaceOrientation在这里是无用的,所以你必须使用notificatons。 在运行时也设置自动布局限制是不可行的。

在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应用旋转变换。 这使您在旋转设备时具有相机应用效果。 我仍然得到一个警告在控制台<Error>: CGAffineTransformInvert: singular matrix. 不知道为什么会发生这种情况,但这是相机视图。

希望以上的帮助。