我的应用使用了几个库。基本KYDrawerController。我希望我的应用程序仅使用potraite Orientation,但是对于一个ViewControllar,我需要landscape和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。
请有人帮助我。
最佳答案
这是我的方式:
您的appdelegae.swift
中的
var shouldSupportAllOrientation = false
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if (shouldSupportAllOrientation == true){
return UIInterfaceOrientationMask.All
}
return UIInterfaceOrientationMask.Portrait
}
@IBAction func next(sender: UIButton) {
let appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appdelegate.shouldSupportAllOrientation = true
self.performSegueWithIdentifier("next", sender: self)
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
let appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appdelegate.shouldSupportAllOrientation = false
}
关于uinavigationcontroller - 应该自动旋转不适用于导航 Controller swift 2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34037274/