I would like to force ViewController to be displayed vertically when the application starts.
func preferredInterfaceOrientationForPresentation()->UIInterfaceOrientation{
return.Portrait
}
is not called.
The SingleView application does not call you when you make a sample as follows:
import UIKit
classViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view, typically from anib.
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func preferredInterfaceOrientationForPresentation()->UIInterfaceOrientation{
return.Portrait
}
override func shouldAutorotate()->Bool{
return true
}
override func supportedInterfaceOrients()->UIInterfaceOrientationMask{
return.All
}
}
How do I get called?
swift
If you insert print(__FUNCTION__)
into each function, you will find that all functions are called normally.
(Verified in Xcode 7.2/Simulator Environment)
This is a way to force the application to appear on a vertical screen, but if you want to do it from the code, you can do it only with the following code:
class ViewController:UIViewController {
override func viewDidLoad(){
super.viewDidLoad()
// Do any additional setup after loading the view, typically from anib.
}
override funcdidReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func supportedInterfaceOrients()->UIInterfaceOrientationMask{
return.Portrait
}
}
More simply, you can specify Device Orientation from Targets - Deployment Info.
class AppDelegate:UIResponder, UIApplicationDelegate{
//...
func application(application:UIApplication,
supportedInterfaceOrientsForWindow:UIWindow?) ->UIInterfaceOrientationMask{
if allowLandscape==false{
return.Portrait
} else{
return.All
}
}
}
We were able to change the allowsLandscape
flag from viewController at a specific time.
© 2024 OneMinuteCode. All rights reserved.