【发布时间】:2015-12-02 07:41:43
【问题描述】:
我的应用程序使用了几个库。基本上是KYDrawerController。我希望我的应用程序仅使用 Potrait 方向,但对于一个 ViewControllar,我需要横向和 Potrait。
我搜索了互联网上几乎所有的解决方案。每个解决方案都是继承 NavigationControllar 和 Override ShouldAutoRotate 方法。但没有一个对我有用。
和here is the closer View of the entire StoryBoard
灰色视图是 KYDrawerControllar 视图,它是一个库,可以像 Android 一样用作 NavigationDrawer。
我为 Navigation Controllar 创建了一个自定义类,并将其子类化为所需的 ViewControllar 的 Navigation Controllar。
这是代码
class SettingsNavigation: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
NSLog("visibleControllar", self.visibleViewController!.debugDescription)
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func shouldAutorotate() -> Bool {
//return self.visibleViewController!.shouldAutorotate()
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
return UIInterfaceOrientation.Portrait
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
这里是 ViewControllar
class Settings: UIViewController {
// MARK: - Outlets
@IBOutlet var profileImage: UIImageView!
@IBOutlet var profileName: UILabel!
@IBOutlet var profileRegistrationType: UILabel!
@IBOutlet var logOutButton: FUIButton!
@IBOutlet var subscriptionType: UILabel!
@IBOutlet var subscriptionRegistrationType: UILabel!
@IBOutlet var upgradeSubscriptionButton: FUIButton!
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;
}*/
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
} }
我正在使用 StoryBoard segues 来展示 ViewControllars。
请有人帮我解决这个问题。
【问题讨论】:
标签: uinavigationcontroller swift2 ios9 xcode7 screen-orientation