簡體   English   中英

在iOS中鎖定一個視圖方向

[英]Lock one view orientation in iOS

我試圖將我的應用程序的一個視圖鎖定為縱向模式。 我有一個頂部導航控制器視圖和多個嵌套場景。

我找到了許多有關鎖定方向問題的答案,並嘗試了下面的代碼,但它僅部分起作用。 讓場景A和B,其中A與B segue ,而B鎖定為縱向。 如果我轉到B場景,請將設備轉到風景位置,然后再返回A,則方向將從先前的B(人像)繼承而來。

如何使A場景識別實際的設備方向?

導航控制器

internal override func shouldAutorotate() -> Bool {
    return visibleViewController!.shouldAutorotate()
}

“ B”視圖控制器

override func shouldAutorotate() -> Bool {
    if UIDevice.currentDevice().orientation == .Portrait {
        return true
    }
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

override func viewDidLoad() {
    super.viewDidLoad()
    let orientation = UIInterfaceOrientation.Portrait.rawValue
    UIDevice.currentDevice().setValue(orientation, forKey: "orientation")
}

據我了解您的問題,您想知道如何獲取當前設備的方向。

嘗試這個...

var orientation = UIDevice.currentDevice().orientation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM