您可以为按钮创建一个操作,在代码中的某处设置一个布尔标志,并shouldAutorotate在视图控制器的方法中返回该标志的值.如果您需要为所有视图控制器,您可以创建一个公共基本视图控制器(继承).
按钮操作示例:
@IBAction func toggleRotation(sender: Button) {
// A made up AppConfig class with class method for setting and retrieving
// rotation flag.
AppConfig.allowRotation(!AppConfig.allowRotation)
}
Run Code Online (Sandbox Code Playgroud)
shouldAutorotate的示例:
override func shouldAutorotate() -> Bool {
return AppConfig.allowRotation()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1357 次 |
| 最近记录: |