Portrait by default, How can some special screens auto rotated or force some screens to landscape?
up vote
2
down vote
favorite
In my app, the orientation is portrait by default, but in some special screens I want the viewcontroller to be auto rotated or to force the orientation to landscape.
in AppDelegate.swift :
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// portrait by default
var interfaceOrientations:UIInterfaceOrientationMask = .portrait {
didSet{
// force to portrait
if interfaceOrientations == .portrait {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue,
forKey: "orientation")
}
// force to landscape
else if !interfaceOrientations.contains(.portrait){
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue,
forKey: "orientation")
}
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return interfaceOrientations
}
in only portrait vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .portrait
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in auto rotated vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .allButUpsideDown
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in only landscape vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = [.landscapeLeft, .landscapeRight]
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
but it still has bugs...Help me
ios swift rotation orientation
add a comment |
up vote
2
down vote
favorite
In my app, the orientation is portrait by default, but in some special screens I want the viewcontroller to be auto rotated or to force the orientation to landscape.
in AppDelegate.swift :
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// portrait by default
var interfaceOrientations:UIInterfaceOrientationMask = .portrait {
didSet{
// force to portrait
if interfaceOrientations == .portrait {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue,
forKey: "orientation")
}
// force to landscape
else if !interfaceOrientations.contains(.portrait){
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue,
forKey: "orientation")
}
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return interfaceOrientations
}
in only portrait vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .portrait
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in auto rotated vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .allButUpsideDown
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in only landscape vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = [.landscapeLeft, .landscapeRight]
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
but it still has bugs...Help me
ios swift rotation orientation
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
In my app, the orientation is portrait by default, but in some special screens I want the viewcontroller to be auto rotated or to force the orientation to landscape.
in AppDelegate.swift :
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// portrait by default
var interfaceOrientations:UIInterfaceOrientationMask = .portrait {
didSet{
// force to portrait
if interfaceOrientations == .portrait {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue,
forKey: "orientation")
}
// force to landscape
else if !interfaceOrientations.contains(.portrait){
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue,
forKey: "orientation")
}
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return interfaceOrientations
}
in only portrait vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .portrait
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in auto rotated vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .allButUpsideDown
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in only landscape vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = [.landscapeLeft, .landscapeRight]
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
but it still has bugs...Help me
ios swift rotation orientation
In my app, the orientation is portrait by default, but in some special screens I want the viewcontroller to be auto rotated or to force the orientation to landscape.
in AppDelegate.swift :
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
// portrait by default
var interfaceOrientations:UIInterfaceOrientationMask = .portrait {
didSet{
// force to portrait
if interfaceOrientations == .portrait {
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue,
forKey: "orientation")
}
// force to landscape
else if !interfaceOrientations.contains(.portrait){
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue,
forKey: "orientation")
}
}
}
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return interfaceOrientations
}
in only portrait vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .portrait
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in auto rotated vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = .allButUpsideDown
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
in only landscape vc:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
appDelegate.interfaceOrientations = [.landscapeLeft, .landscapeRight]
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
appDelegate.interfaceOrientations = .portrait
}
but it still has bugs...Help me
ios swift rotation orientation
ios swift rotation orientation
edited Nov 8 at 13:53
Ratul Sharker
2,14211524
2,14211524
asked Nov 8 at 10:20
desmond_yy
111
111
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
You should force the rotation with:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
You also have to enable autoRotation
override var shouldAutorotate: Bool{
return true
}
And of course, in your project settings you have to enable both portrait and landscapes modes.
add a comment |
up vote
0
down vote
You can custom your Portrait View Controller and Landscape View Controller. LandscapeViewController like this:
```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
```
Some points need to notice: UIViewController can't decide to rotate automatically, you can use UINavigationController to fetch the value of rotation property:
override var shouldAutorotate: Bool {
return (self.topViewController?.shouldAutorotate)!
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return (self.topViewController?.preferredInterfaceOrientationForPresentation)!
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You should force the rotation with:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
You also have to enable autoRotation
override var shouldAutorotate: Bool{
return true
}
And of course, in your project settings you have to enable both portrait and landscapes modes.
add a comment |
up vote
0
down vote
You should force the rotation with:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
You also have to enable autoRotation
override var shouldAutorotate: Bool{
return true
}
And of course, in your project settings you have to enable both portrait and landscapes modes.
add a comment |
up vote
0
down vote
up vote
0
down vote
You should force the rotation with:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
You also have to enable autoRotation
override var shouldAutorotate: Bool{
return true
}
And of course, in your project settings you have to enable both portrait and landscapes modes.
You should force the rotation with:
UIDevice.current.setValue(UIInterfaceOrientation.landscapeLeft.rawValue, forKey: "orientation")
You also have to enable autoRotation
override var shouldAutorotate: Bool{
return true
}
And of course, in your project settings you have to enable both portrait and landscapes modes.
answered Nov 8 at 10:51
Juan Curti
1,8501130
1,8501130
add a comment |
add a comment |
up vote
0
down vote
You can custom your Portrait View Controller and Landscape View Controller. LandscapeViewController like this:
```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
```
Some points need to notice: UIViewController can't decide to rotate automatically, you can use UINavigationController to fetch the value of rotation property:
override var shouldAutorotate: Bool {
return (self.topViewController?.shouldAutorotate)!
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return (self.topViewController?.preferredInterfaceOrientationForPresentation)!
}
add a comment |
up vote
0
down vote
You can custom your Portrait View Controller and Landscape View Controller. LandscapeViewController like this:
```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
```
Some points need to notice: UIViewController can't decide to rotate automatically, you can use UINavigationController to fetch the value of rotation property:
override var shouldAutorotate: Bool {
return (self.topViewController?.shouldAutorotate)!
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return (self.topViewController?.preferredInterfaceOrientationForPresentation)!
}
add a comment |
up vote
0
down vote
up vote
0
down vote
You can custom your Portrait View Controller and Landscape View Controller. LandscapeViewController like this:
```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
```
Some points need to notice: UIViewController can't decide to rotate automatically, you can use UINavigationController to fetch the value of rotation property:
override var shouldAutorotate: Bool {
return (self.topViewController?.shouldAutorotate)!
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return (self.topViewController?.preferredInterfaceOrientationForPresentation)!
}
You can custom your Portrait View Controller and Landscape View Controller. LandscapeViewController like this:
```
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.landscapeRight.rawValue, forKey: "orientation")
}
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .landscapeRight
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return .landscapeRight
}
```
Some points need to notice: UIViewController can't decide to rotate automatically, you can use UINavigationController to fetch the value of rotation property:
override var shouldAutorotate: Bool {
return (self.topViewController?.shouldAutorotate)!
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations)!
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return (self.topViewController?.preferredInterfaceOrientationForPresentation)!
}
edited Nov 9 at 2:11
answered Nov 9 at 1:58
ZeroOnet
65
65
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205704%2fportrait-by-default-how-can-some-special-screens-auto-rotated-or-force-some-scr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown