a short question.
I've created an app for the iPad, much like a utility app for the iPhone (one mainView, one flipSideView). The animation between them is UIModalTransitionStylePartialCurl.
shouldAutorotateToInterfaceOrientation is returning YES.
If I rotate the device BEFORE entering the FlipSide, everything is okay and the PartialCurl is displayed okay.
But if I enter the FlipSide and then rotate the device, while the UIElements do rotate and position themselves just fine, the actual "page curl" stays with its initial orientation. it just won't budge :)
Is it a known issue? am I doing something wrong?
Thanks!
I too had this issue and somewhat gave up. However, I mentioned my dilemma to a friend, who encouraged me to look into the child VC's logic and I recalled a handy trick that I've used to pass data between parent/child view controllers.
In your flipside view controller, create a "rootViewController" property. In your parent view controller, when you initialize the flipside view controller, you set (where "self" is the rootVC):
flipsideController.rootViewController = self;
You then use this for your flipside VC's shouldAutorotateToInterfaceOrientation method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return interfaceOrientation == self.rootViewController.interfaceOrientation;
}
Viola! The flipside view no longer rotates underneath the partially curled up parent view!
The shortest way of the above code is:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == self.parentViewController.interfaceOrientation;
}
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];
}
I have this method in my MainViewController:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(#"MAIN CONTAINER WILL ANIMATE");
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
And when I rotate, the NSLog shows up, and everything is perfect. However, if I present a modalViewController from my MainViewController, and then I rotate, the NSLog no longer appears, and my MainViewController never knows that the device got rotated, so when the modalView is dismissed, the interface is not adjusted for the rotation.
Any ideas as to why a modal view can prevent the parent from receiving rotation updates? Is this typical, or must there be something wrong with my setup?
And just to make sure, I tried presenting the modalViewController as a subview via [mainViewController.view addSubview:modalView.view], and the rotation updates took effect properly. It's only when I do [mainViewController presentModalViewController:modalViewController]; that the updates don't take effect.
Surely when a view controller is being presented modally, no other view controllers receive any messages at all. That is what modal means in this context.
The obvious solution would be to check the orientation in the viewWillAppear method of your modeless view controller.
You have to check the implementation of:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
In both views.
You need to adjust your layout to the current interface orientation in viewWillAppear. Obviously, because the view is not visible, the animation functions will not be called while the modal view controller is up.
i have a tabbar application and as you may know, you have to return YES in the shouldAutorotate method in every view controller for the views to be able to rotate. My problem is that i want to prevent a view from rotating and if i return NO then the other views won't rotate either. Is there a work around for this? Info: i'm not subclassing UITabbarController in any of my views.
Thanks in advance.
In theory you could check in shouldAutorotate what the current view is:
if ( currentView == viewThatShouldNotRotate )
return NO;
However, shouldAutorotate is only called when changing the view controller. If you want only one view to autorotate, consider giving it its own view controller that the UITabBarController can present as a modal view. You'll have to handle the navigation logic yourself though.
Use the ShouldAutoRotateToInterFaceOrientation: method
[self.navigationController
shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
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 have a view controller which manages a view.
I'm adding the my view controller subclass as a subview of the window swapping out another view.
I'm running landscape mode on an iPad.
The view apparently doesn't know that its in landscape mode. Its frame is confused.
Is there something I can/should do to tell it that its in landscape, and/or that the orientation has changed. How does this normally happen. Why isn't it happening?
I used to have my view controller within a UITabBarController and it worked fine there.
Override:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
Your ViewController is not getting rotation events because you have not presented the viewController but have added the viewController's view in the view hierarchy.
Your Tab bar controller previously used to take the responsibility to forward the rotation events to the view controller which it manages, that was how it used to work.
I would though suggest that swapping the view out of window is a bad idea. Instead you should have a main viewController which accepts the rotation events and then swap the view within this viewController based on the current orientation. Consider re-desiging before you code further.
My problem was that my storyboard was overriding my existing custom coded app delegate. After I deleted the story board file, and custom generated view controller code, it worked for me.