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

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

从这幅肖像(B是UIButtons)

  1. |-----------|
  2. | |
  3. | |
  4. | |
  5. | |
  6. | |
  7. | |
  8. | B B B |
  9. |-----------|

到了这个景观

  1. |----------------|
  2. | B |
  3. | |
  4. | B |
  5. | |
  6. | B |
  7. |----------------|

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

解决方法

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

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

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

  1. // send notification on rotation
  2. [[UIDevice currentDevice]beginGeneratingDeviceOrientationNotifications];

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

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

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

  1. - (void)orientationChanged:(NSNotification *)notification
  2. {
  3. UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  4. double rotation = 0;
  5.  
  6. switch (orientation) {
  7. case UIDeviceOrientationPortrait:
  8. rotation = 0;
  9. break;
  10. case UIDeviceOrientationPortraitUpsideDown:
  11. rotation = M_PI;
  12. break;
  13. case UIDeviceOrientationLandscapeLeft:
  14. rotation = M_PI_2;
  15. break;
  16. case UIDeviceOrientationLandscapeRight:
  17. rotation = -M_PI_2;
  18. break;
  19. case UIDeviceOrientationFaceDown:
  20. case UIDeviceOrientationFaceUp:
  21. case UIDeviceOrientationUnknown:
  22. default:
  23. return;
  24. }
  25. CGAffineTransform transform = CGAffineTransformMakeRotation(rotation);
  26. [UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
  27. self.btnCancel.transform = transform;
  28. self.btnSnap.transform = transform;
  29. }completion:nil];
  30. }

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

希望以上有所帮助.

猜你在找的iOS相关文章