[注意] このコードは iPhone では期待通りに動作しますがiPad では回転方向を制限できません。 iPadに関してはこちらを参照して下さい。


|
|
| 縦向き+横向きの設定 | 縦向きのみの設定 |
Portrait Landscape Left Landscape Rightにチェックが入った状態(デフォルトのまま)にします。

| ViewController2.swiftに追加するコード(赤字部分) |
import UIKit
class ViewController2: UIViewController {
@IBAction func tapBack(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
|


|
| |
| Deployment Infoの設定 | ViewController.swiftに追加するコード |