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.
Related
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.
I use to define my UIViews programmatically, setting the orientation via code. I haven't touched Interface Builder in a while and I've decided to go for the new Storyboarding system.
I was pretty happy until I found out that although I have set, in the inspector pane, the appropriate view controller to "Landscape", it never displays in another mode than portrait.
I commented in and out the code in my custom view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
Nothing changes.
My View Controller is itself "under" a Navigation Controller on the Storyboard, so I suspect interference, and it's only the second view in the flow, so the fact that the application itself is defined as portrait should not interfere.
I am looking for ideas to test for at this point, since the application is stripped to so little code I really can't begin to guess where to look?
What supported orientations have you specified in Info.plist? In order for a UINavigationController to support rotation, all of it's child view controllers must also support rotation to the same orientation.
I'm working on an iphone app with tab bars each one associated to a navigation controller. In one of these controllers I've a Table View showing some listing and when a row is selected another view displays specific informations and a button to see some related photos.
I'm having an issue displaying the photo view in landscape.
The photo view controller contains a UIImageView to display one photo at a time and this ImageView object size is 320x460 showing in full screen mode. To handle rotation I've added the following code:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But it's not rotating and iphone simulator status bar is still in the portrait position, so not rotated too.
I've also changed the method like this:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Still no changes on device rotation. And the options in Project->Summary(Tab)->Supported Device Orientation->Desired Orientations clearly enable landscape mode (right/left).
Can you help me understand what I may be missing ?
Thx for helping,
Stephane
With a tab bar controller, it will only rotate if your view controllers for all your tabs allow the orientation. Kind of annoying, but there it is. You need to override shouldAutorotateToInterfaceOrientation in all your other view controllers too, and they need to be able to smoothly adjust to those orientations.
If it's not practical to support landscape orientations on the other view controllers, maybe you could try some hacking, for example by subclassing UITabBarController and overriding its shouldAutorotateToInterfaceOrientation to instead return YES if the current view controller returns YES. But that might get your app rejected as not conforming to Human Interface Guidelines, since you are trying to circumvent standard interface behavior.
Check if you're not in some sort of a subclassed container view controller (like your own UINavigationController or UITabBarController subclasses). If that's the case make sure it does not override shouldAutorotateToInterfaceOrientation: method.
Your looking in the wrong place: in your RootViewController.m file look for the following code:
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
//lots of useless comments
//
return (UIInterfaceOrientationIsPortrait(interfaceOrientation) ); //THIS LINE HERE
// return (UIInterfaceOrientationIsLandScape(interfaceOrientation) );
the line that says return (UIInterface... Portrait) is the line that determines your app's rotating capabilities. You can change this to whatever to allow you to be able to rotate completely, keep it at a certain orientation, or whatever you desire...
I am working on an iPhone app with a UINavigationController interface and there I want all views to ONLY allow default portrait rotation except for one. I know I can return 'NO' in the shouldAutoRotate method but basically when I am in the view that does allow rotation and go back to the previous view, the other views are then stuck in landscape as well. Any ideas?
you need to change status bar orientation when you go back to previous view.
It's a small but annoying issue. I'm using a navigation controller and it will not rotate. I was using the code before without a navigation controller and it was rotating beautifully. It isn't even calling "-(BOOL)shouldAutororateToInterfaceOrientation..." now so I'm at a bit of a loss.
Thanks in advance.
Edit: And yes I have "-(BOOL)canBecomeFirstResponder" set.
Edit2: I have it calling "-(BOOL)shouldAutororateToInterfaceOrientation..." now when the App first runs and at this point the screen is rotated but then when it shows the Navcontroller sets it back to portrait mode...
There's a problem with UIWindow propagating these events to view controllers other than the root one. If you're adding this controller directly to a UIWindow and it isn't the first one you've added, then add it to the root view instead.
Otherwise, you'll probably need to take a look at implementing your own rotation transformations. I've got a UIViewController subclass which does the heavy lifting for you on github here.
Your controller need to have return YES in:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
Also if you have an UITabBarController, each controllers need that method to return YES.