答案 0 :(得分:2)
将此行代码添加到viewDidLoad方法: func rotate(){
if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft {
self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
} else if UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight {
self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI_2))
} else if UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait {
self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(0))
self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(0))
} else if UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown {
self.takephoto.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
self.recordButton.transform = CGAffineTransformMakeRotation(CGFloat(M_PI))
}
}
这就是功能:
print
答案 1 :(得分:0)
从支持纵向模式开始。您可以在控制器中观察UIDeviceOrientationDidChangeNotification,例如: https://stackoverflow.com/a/12086463/4209778
然后根据您的方向,您可以使用CGAffineTransformMakeRotation旋转图标(+/-)90度。
答案 2 :(得分:0)
在您的视图控制器中覆盖viewWillTransitionToSize:withTransitionCoordinator:
并使用以下代码表示您的图像:imageView.transform = CGAffineTransformMakeRotation(CGFloat(M_PI_2))
EG:
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
let isPortrait = size.height > size.width
imageView.transform = CGAffineTransformMakeRotation(CGFloat(isPortrait ? 0 : M_PI_2))
}