I've recently added landscape autorotation to my iPhone navigation based application, however I'm having a bizarre issue which I have no idea how to fix or whether my code is even the cuplrit. Its bizarre because I'm implementing everything as per the autorotation docs on Apple's developer center (that is responding to shouldAutorotateToBlaBla and making sure my views autoadjust correctly).
The problem is that while pushing view controllers animates correctly, popping them off causing the animation to sometimes shift 20px then animate UP the screen, not from right to left relative to the current rotation.
In other words, when you hit Back in a landscape view controller, instead of animating to the right off the screen, it animates vertically down as if it was in Portrait orientation.
Any clues?
I had this bug, but fixed it by implementing this UIViewController method in every view controller I had.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == UIInterfaceOrientationPortrait | UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
Related
I am using IIViewDeckController and facing a very weird problem as follows?:
My ViewController(which is an IIViewDeckController) is in landscape mode and then I present a new view controller modally on top of it. Now the modal view controller does not support landscape mode and thus is presented only in portrait mode.
As of now, everything went fine.
But as soon as I try to dismiss this modally presented controller, IIViewDeckController's view's frame becomes (320,568) (I think this IIViewDeckController has rotated to portrait mode but I am not sure for that). So I checked self.interfaceOrientation which showed "4"(i.e. UIInterfaceOrientationLandscapeLeft) which should be the actual case.
But these two things are confusing me as the frame is indicating the portrait mode and property shows something different. Now because of this frame changing without changing the interfaceOrientation is result into wrong calculation of objects' frames in the view.
I faced the same problem, I solved it by categorizing IIViewDeckController inside AppDelegate class.
Following is the one method that was required to be categorized:-
#interface IIViewDeckController (categoryForOrientation)
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
#end
#implementation IIViewDeckController (categoryForOrientation)
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return [self interfaceOrientation];
}
supportedInterfaceOrientation should be called only once when viewDidLoad, but in my case it is called every time the simulator rotates.
I need only two orientations potrait and portrait upside down.
when i rotate to upside down the supported interface orientation is called 4 times and my view becomes upside down. on rotation to landscape it is called only once(but it shouldn't ?).
Any solution ?
PS: I am not using any Navigation controller so setting rotation equal to top view controller wont matter. And in my pList only 2 orientations are supported
Also I have a main View Controller in which I add subviews and I have set the supported interface orientation in my view controller.
Weird thing is 3 view controllers that are before(presented before) the faulty one, they
rotate just fine.
You can check the interfaceOrientation in viewDidLoad. You can get the interfaceOrientation with self.userInterFaceOrientation.
Maybe it would be better to check the interfaceOrientation in viewWillAppear.
The difference is, that viewDidLoad will only called one and viewWillAppear every time you enter that view.
Its so Simple you just click on your Project -> Summary -> Supported Interface Orientations. You can click the Interface Orientations as your requirements.
I have a UITabBar with 2 bar items. The initial orientation of the device is portrait. If I rotate the device to landscape while being at tabBarItem2 the whole thing(Status Bar, TabBar, ViewContent2) rotates fine, but when I press the tabBarItem1 the ViewContent1 is still in Portrait. It also happens if I'm in tabBarItem1, then rotate device to landscape and I go to tabBarItem2.
I'm using the willRotateToInterfaceOrientation method on each view controller to move things.
I think this is happening because it is triggering the actual viewController's willRotateToInterfaceOrientation method and not on both of them.
Any ideas on how to fix that?
Both view controllers need to have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
I have an app for the iPad/iPhone and Portrait and Landscape is working just fine. However, I recently added a TabViewController and a second tab with a view. Problem is when I click my second view and rotate and then switch back to the first view my controls are not repositioned
Can anyone tell me what I need to do so that I can reposition my views when the first view is clicked?
incidentally, I am assuming I will have the same problem the other way too... view 2 to view 1.
Did you checked that all your view controller implement this method ?
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
From my experience, the same problem also occurs with navigation controller. I guess that the framework wont send the rotation event to every hidden VC on purpose to save processing time. The solution I ever did is just overriding viewWillAppear and correctly layout subviews there if needed.
I am using a UINavigationController to push and pop views. The Navigation bar is hidden.
I have RootViewController, which is set to autorotate. It works just fine when it is visible.
I also have GalleryViewController. It has autorotation disabled by just returning no.
My problem is, when GalleryViewController is on the nav stack, RootViewController stops responding to it's autorotate events.
If I am in Portrait, and I rotate the device (while viewing GalleryViewController) and then tap the back button, it pops the GalleryViewController off the stack and reveals the RootViewController, but RootViewController did not change rotation as it should have.
I stuck in the method -viewWillAppear and checked the status of the UIDevice orientation. It gives me the correct orientation for the device.
BTW, I also tried enabling the autorotate in the GalleryViewController. It then rotates the view correctly but still does not rotate the RootViewController.
It seems that when using the navigation controller, only the top of the stack gets rotated.
QUESTION: Since the device knows it's in the correct rotation when -viewWillAppear is called, can I force it to update somehow??
-mark
instead of returning just YES, return (interfaceOrientaion == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || and so on...) in the RootViewController.
in the GalleryViewController return only one orientation which in our opinion is the default one.
When thus done - everything should work like you want it.