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

时间:2013-04-08 18:35:23

标签: ios uiimagepickercontroller landscape portrait

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

从这张照片(B是UIButtons)

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

到这个景观

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

换句话说,我希望这些按钮能够粘在原始的肖像底部并在其中心旋转。我正在使用Storyboard并启用了Autolayout。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:16)

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

要捕获旋转,willRotateToInterfaceOrientation在这里没用,所以你必须使用通知。在运行时设置autolayout约束也不是可行的方法。

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

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

在cameraOverlayView viewDidLoad的{​​{1}}方法中添加以下内容:

UIViewController

最后将//add observer for the rotation notification [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 方法添加到cameraOverlay orientationChanged:

UIViewController

上面的代码在我使用的2个UIButtons上应用了旋转变换,在这种情况下是btnCancel和btnSnap。这样可以在旋转设备时为您提供相机应用效果。 我仍然在控制台- (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]; } 中收到警告,不知道为什么会发生这种情况,但这与摄像机视图有关。

希望以上有所帮助。