第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在Swift iOS中設(shè)置設(shè)備方向

在Swift iOS中設(shè)置設(shè)備方向

阿晨1998 2019-09-21 13:41:01
我正在為iPhone開(kāi)發(fā)一個(gè)快速的應(yīng)用程序。我的應(yīng)用程序中有一個(gè)模式視圖,我只想使用縱向視圖。我的問(wèn)題是,如何以編程方式強(qiáng)制手機(jī)不允許旋轉(zhuǎn)?換句話說(shuō),我正在尋找的代碼不允許以橫向模式顯示模式視圖(打開(kāi)人像旋轉(zhuǎn)鎖定)。這僅用于1個(gè)模式視圖,因此我無(wú)法關(guān)閉整個(gè)應(yīng)用程序的旋轉(zhuǎn),否則我將完全禁用旋轉(zhuǎn)。我在這里的研究中找到了代碼, 但如果有幫助,它在目標(biāo)C中。謝謝!
查看完整描述

3 回答

?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超7個(gè)贊

您可以將這些方法粘貼到每個(gè)需要縱向顯示的視圖的ViewController中:


override func shouldAutorotate() -> Bool {

    return false

}


override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    return UIInterfaceOrientationMask.Portrait

}


查看完整回答
反對(duì) 回復(fù) 2019-09-21
?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗(yàn) 獲得超7個(gè)贊

Hi for LandscapeLeft和LandscapeRight (更新Swift 2.0)

http://img1.sycdn.imooc.com//5d85b82300014aa907580172.jpg

你有這個(gè)信息

http://img1.sycdn.imooc.com//5d85b8250001072c11000376.jpg

和UIController


override func shouldAutorotate() -> Bool {

    return true

}


override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    return [UIInterfaceOrientationMask.LandscapeLeft,UIInterfaceOrientationMask.LandscapeRight]

}

對(duì)于PortraitUpsideDown和Portrait使用 

http://img1.sycdn.imooc.com//5d85b8310001136805700170.jpg

override func shouldAutorotate() -> Bool {

    if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft ||

        UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight ||

        UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {

            return false

    }

    else {

        return true

    }

}


override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    return [UIInterfaceOrientationMask.Portrait ,UIInterfaceOrientationMask.PortraitUpsideDown]

}

法國(guó)寄語(yǔ),圣誕快樂(lè)!


編輯:


其他解決方案:


extension UINavigationController {

    public override func shouldAutorotate() -> Bool {

        if visibleViewController is MyViewController {

            return true   // rotation

        } else {

            return false  // no rotation

        }

    }


    public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

        return (visibleViewController?.supportedInterfaceOrientations())!

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-09-21
?
泛舟湖上清波郎朗

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個(gè)贊


如果將視圖控制器嵌入U(xiǎn)INavigationController或UITabBarController中,則定向旋轉(zhuǎn)會(huì)更加復(fù)雜,導(dǎo)航或選項(xiàng)卡欄控制器將具有優(yōu)先權(quán)并就自動(dòng)旋轉(zhuǎn)和支持的定向做出決策。


在UINavigationController和UITabBarController上使用以下擴(kuò)展,以便嵌入在這些控制器之一中的視圖控制器可以做出決定:


UINavigationController擴(kuò)展


extension UINavigationController {


override open var shouldAutorotate: Bool {

? ? get {

? ? ? ? if let visibleVC = visibleViewController {

? ? ? ? ? ? return visibleVC.shouldAutorotate

? ? ? ? }

? ? ? ? return super.shouldAutorotate

? ? }

}


override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{

? ? get {

? ? ? ? if let visibleVC = visibleViewController {

? ? ? ? ? ? return visibleVC.preferredInterfaceOrientationForPresentation

? ? ? ? }

? ? ? ? return super.preferredInterfaceOrientationForPresentation

? ? }

}


override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{

? ? get {

? ? ? ? if let visibleVC = visibleViewController {

? ? ? ? ? ? return visibleVC.supportedInterfaceOrientations

? ? ? ? }

? ? ? ? return super.supportedInterfaceOrientations

? ? }

?}}

UITabBarController擴(kuò)展


extension UITabBarController {


override open var shouldAutorotate: Bool {

? ? get {

? ? ? ? if let selectedVC = selectedViewController{

? ? ? ? ? ? return selectedVC.shouldAutorotate

? ? ? ? }

? ? ? ? return super.shouldAutorotate

? ? }

}


override open var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{

? ? get {

? ? ? ? if let selectedVC = selectedViewController{

? ? ? ? ? ? return selectedVC.preferredInterfaceOrientationForPresentation

? ? ? ? }

? ? ? ? return super.preferredInterfaceOrientationForPresentation

? ? }

}


override open var supportedInterfaceOrientations: UIInterfaceOrientationMask{

? ? get {

? ? ? ? if let selectedVC = selectedViewController{

? ? ? ? ? ? return selectedVC.supportedInterfaceOrientations

? ? ? ? }

? ? ? ? return super.supportedInterfaceOrientations

? ? }

}}

現(xiàn)在,您可以在要鎖定的視圖控制器中重寫(xiě)supportedInterfaceOrientations,shouldAutoRotate和preferredInterfaceOrientationForPresentation,否則可以在其他視圖控制器中忽略要繼承應(yīng)用程序plist中指定的默認(rèn)方向行為的替代。


鎖定特定方向


class YourViewController: UIViewController {

open override var supportedInterfaceOrientations: UIInterfaceOrientationMask{

? ? get {

? ? ? ? return .portrait

? ? }

}}

禁用旋轉(zhuǎn)


? ? class YourViewController: UIViewController {

open override var shouldAutorotate: Bool {

? ? get {

? ? ? ? return false

? ? }

}}

更改演示的首選界面方向


class YourViewController: UIViewController {

open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation{

? ? get {

? ? ? ? return .portrait

? ? }

}}


查看完整回答
反對(duì) 回復(fù) 2019-09-21
  • 3 回答
  • 0 關(guān)注
  • 1063 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)