ios - 当 iPad 处于横屏模式时 Swift 旋转图标

标签 ios swift rotation icons

目前我的应用程序在纵向模式下看起来像这样: enter image description here

但是当我的 iPad 处于横向模式时,我希望我的图标看起来像这样: enter image description here

现在它在横向模式下看起来像这样:

enter image description here

所以我的问题是:我怎样才能旋转图标?我不需要更多的东西只是图标应该移动

最佳答案

将这行代码添加到 viewDidLoad 方法中:NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(rotate), name: UIDeviceOrientationDidChangeNotification, object: nil)
这是函数:

    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))
 }
}

关于ios - 当 iPad 处于横屏模式时 Swift 旋转图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38590258/

相关文章:

c# - Unity - 任意角度之间的夹具旋转

ios - 呈现 Modal ViewController 时出现方向问题

swift - 是否可以向 Swift 协议(protocol)一致性扩展添加类型约束?

ios - 内部绘图旋转 UIView 时出现问题

Swift 在滑动时保留 UIPageViewController 中的文本字段内容

ios - 我想通过在 Swift 中以编程方式将 UINavigationController 与 UITableViewController 嵌入,这是 UITabBarViewController 的 subview

ios - 尝试解决 iOS 中的旋转问题

iphone - becomeFirstResponder 不隐藏键盘

objective-c - Objective -c 委托(delegate)语法查询

jquery - IOS HTML5 应用程序中的 iScroll4 js - 滚动到最上面的问题