2017-01-27 9 views
-1

iOSユニバーサルアプリケーションで自動レイアウトの作業が終了し、完全にポートレートで作業しています。しかし、私は、ユーザーがデバイスを回転させて、風景モードでゲームをプレイできるようにしたい。私が直面している問題は、レイアウトをまったく変えたくないということです。ゲームのコントロールを変更するだけです(画面をスライドさせると、プレイヤーは両方の向きになるはずです)。iOS - レイアウトを横向きにしているが、コントロールを変更する

どういうわけか、向きを変えて向きを変えないようにすると同時に、向きに基づいて動作を変更することはできません。あなたは私がそれをどのように管理できるか考えていますか?

答えて

0

オリエンテーションが無効になっているときに、デバイスの向きに(インターフェイスの向きではなく)アクセスでき、変更に応じて動作するように通知する方法を見つけましたか?

class ViewController: UIViewController { 
    var currentOrientation = 0 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Register for notification about device orientation change 
     UIDevice.current.beginGeneratingDeviceOrientationNotifications() 
     NotificationCenter.default.addObserver(self, selector: #selector(deviceDidRotate(notification:)), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil) 
    } 

    // Remove observer on window disappears 
    override func viewWillDisappear(_ animated: Bool) { 
     super.viewWillDisappear(animated) 

     NotificationCenter.default.removeObserver(self) 
     if UIDevice.current.isGeneratingDeviceOrientationNotifications { 
      UIDevice.current.endGeneratingDeviceOrientationNotifications() 
     } 
    } 

    // That part gets fired on orientation change, and I ignore states 0 - 5 - 6, respectively Unknown, flat up facing and down facing. 
    func deviceDidRotate(notification: NSNotification) { 
     if (UIDevice.current.orientation.rawValue < 5 && UIDevice.current.orientation.rawValue > 0) { 
      self.currentOrientation = UIDevice.current.orientation.rawValue 
     } 
    } 


} 
関連する問題