I have app in portrait oriantation for all the view's.
I need to make a landscape for specific views.
I found this.
Put this in the viewDidLoad():
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
and,
override func shouldAutorotate() -> Bool {
return true
}
the problem is that this function only works if I enable landscape right and left mode, and i don't want my app to support landscape.
It seems that you could mark Landscape Right and Landscape Left, then use shouldAutorotate in your views accordingly, but the link below suggests a better method.
I believe this will answer your question: http://swiftiostutorials.com/ios-orientations-landscape-orientation-one-view-controller/
You can check if the rootViewController contains a "presented controller" and if it does then that class is checked. Thus, if the "check" goes through the UIInterfaceOrientationMaskAll (allowing Landscape mode) is returned. If it doesn't then Portrait mode defaults.
I downloaded the sample project in swift and got everything up and running smoothly.
Hope this helps.
If you do not want your app to support landscape, you can not have a specific view controller forced in landscape, when it loads or whenever you need it.
Related
I have a systemic portrait-mode storyboard.
However I want to be able to rotate one scene to landscape mode without affecting other storyboard scenes.
Is this possible and how would I implement it?
Override the supportedInterfaceOrientations method in the view controller you want to allow landscape in, to return UIInterfaceOrientationMaskAllButUpsideDown or whichever value is suitable. This property is also configurable from the storyboard.
This will not affect the possible orientations of other view controllers; the app's UI orientation will automatically change back to portrait when you go to another scene.
You might need to uncheck Device Orientation options located in the project's General Settings for this to take effect (I didn't need to, but it seems to be necessary for some people):
I've read to many posts but I can't find a solution.
I've a tabbed application using storyboard. All the View Controllers of that Tabbed Application must show the content in portrait orientation, but there's only one viewcontroller (which is showing a video) that I want to be in landscape mode.
EXPLANATION OF THE STORYBOARD: TabBarController -> 4x Navigation controllers -> each navigation controller points to his ViewController -> one of these view controllers have an image, when I press that image, i've done a push to another view, the view that I want to have in landscape mode because I have there a UIWebView to show a video.
I'm unable to have all the app only in portrait orientation and the viewcontroller mentioned capable to rotate in landscape mode.
My app is also supporting iOS 5, so I know there are methods deprecated and I'm getting crazy.
I believe that in Summary > iPhone / iPod Deployment info > Supported Interface Orientations > there I've to check Portrait, Landscape left and right, and then via methods, enable or disable the rotations. I'm lost.
Can you help me?
I think you should be able to do this if you push to the view as a modal. Make sure your application's PList file (under Supporting Files folder) is set to support all orientations and then simply add the code to the modal view controller to display landscape with something like this.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Let me know if you have any luck.
As i worked out for my App i advise you to use this solution.By using some conditions in the shouldAutorotateToInterfaceOrientation method orientation type we can solve this.Just try with this link will help you.
https://stackoverflow.com/questions/12021185/ios-rotate-view-only-one-view-controllers-view/15403129#1540312
I´m making an app for a Zoo, and it is very simple, but because at fisrt I tried to make it with code and using xcode 3.2, but I had some problems so I started it with Xcode 4.3 and am trying it with the storyboards.
My question is, how could I put all the app in landscape mode? I mean I already set it in the infoplist: the initial interface orientation, and then in the .m file I changed the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationLandscapeRight;
}
But it doesn´t work. When I add a tabbarcontroller and link it all the views become portrait. The first one if I rotate it it does give me the landscape but all the others are always in portrait, so what can I do?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation==UIInterfaceOrientationLandscapeRight;
}
When you add tabbar controller on storyboard, in attribute inspector of tab bar you have orientation that is on inferred by default, change it to Landscape. But is better you set orientation from summary tab of project to Landscape Right. it lets your up come up on Right landscape.
In my application, i have used UITabbarController inside UINavigationController, when you click main it will landed to detail with landscape, instead of that, i need to change the orientation of my app. how should i get it?
Sri
You can't force an orientation, that requires the use of a private API. What you need to do is implement the following method on your view controller and return yes for only the supported orientations. For example, if you support only the portrait orientation add this:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
return ((orientation==UIInterfaceOrientationPortrait) || (orientation==UIInterfaceOrientationPortraitUpsideDown))
}
Also note that you have to override that method (copy&paste) in every view controller class of your hierarchy because of this.
Hope it helps, I'm not sure if that is what you asked for.
I'm strugging with getting an iPhone application which requires just about every push or pop in the Nav Controller Stack to change orientation.
Basically the first view is portrait, the second landscape the third portrait again (Yes I know this is less than ideal, but that's the design and I've got to implement it).
I've been through various advice on here....
How do I detect a rotation on the iPhone without the device autorotating?
Force portrait orientation on pushing new view to UINavigationViewController
Is there a documented way to set the iPhone orientation?
But without total success.
Setting to link against 3.1.2 my reading of the linked articles above seems to indicate that if my portrait view pushes a view with
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}
Then then that view should appear rotated to landscape. What happens is it appears in its "broken" portrait form, then rotates correctly as the device is turned.
If I pop the controller back to my portrait view (which has an appropriate shouldAutoRotate...) then that remains in broken landscape view until the device is returned to portrait orientation.
I've also tried removing all the shouldautorotate messages, and instead forcing rotation by transforming the view. This kind of works, and I've figured out that by moving the status bar (which is actually hidden in my application) [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; the keyboard will appear with the correct orientation when desired.
The problem with this approach is that the status bar transform is weird and ugly when you don't have a status bar - a shadow looms over the page with each change.
So. What am I missing.
1) Am I wrong in thinking that in 3.1.2 (or possibly earlier) shouldAutorotateToInterfaceOrientation should provide the desired orientation simply by pushing controllers ?
2) Is there another way of getting keyboards to appear in the correct orientation.
3) Are the undocumented API calls the way to go (please no!)
You shouldn't use [UIViewController shouldAutorotateToInterfaceOrientation:] to trigger an orientation change; it's only there to let the system know if automatic rotations are allowed. You should still update it to specify the orientation that's allowed though.
If you want to change the orientation when a particular view is showing, you should call [UIApplication setStatusBarOrientation:animated:] inside your [UIViewController viewWillAppear:] override method for each of the view controllers that force a particular orientation. That will cause a change when a view is being pushed onto the stack and when it's being popped off it. Make sure you call super in your override method.
This is also the right place to change how the status bar is displayed, if that's something you're doing.