View controllers inside tab bar controller not auto-resizing on rotation - iphone

(Correction: the view controllers are not auto-resizing instead of not auto-rotating.)
In an iPad app, I have five regular view controllers (not navigation controllers or anything like that) inside a tab bar controller. The tab bar controller is just a plain UITabBarController declared in the app delegate.
All the view controllers return YES in the shouldAutorotateToInterfaceOrientation method.
On both the simulator and device, on rotation, the tab bar and the current view controller rotate but the currently selected view controller (call it A) does not resize properly. It keeps its portrait width and height (but it is rotated).
If I switch to another view controller B and then back to A (without rotating the device again), A appears correctly resized.
This happens with any of the five view controllers
Why doesn't the currently selected view controller resize immediately on rotation and how do I fix it?
Thanks.

You should add :
self.view.autoresizesSubviews = YES;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
To each viewDidLoad method of the sub-viewcontrollers of your tabbar controller.

Related

Tab bar gets covered by the new view

I have built an app based on a tab bar controller. While I am on one of the tab views I want to be able to swipe my finger and switch to another tab view of which the index on the tabBarController in unknown. I am therefore calling the desired viewcontroller from its nib. The view gets swapped correctly but the problem is that it appears ABOVE the tab bar itself, covering it completely and making it become unusable! How can I push the view back or the tab bar up? Thanks
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender
{
DesiredViewController *controllerInstance =[[DesiredViewController alloc]initWithNibName:#"DesiredViewController" bundle:nil];
controllerInstance.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controllerInstance animated:YES];
}
presentModalViewController:animated always uses whole screen: On iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.
If you really use UITabBarController, it instantiates view controllers of its tabs. So trying to instantiate view controller of one of tabs manually is wrong. You will end in a mess of view controllers instances.
Set property selectedIndex of your UITabBarController to switch tab. I think you need this. But it will be switched without animation.
If you know only pointer of controller you want to switch to, ask viewControllers property about controller's index and than switch tab by its index:
self.selectedIndex = [[self viewControllers] indexOfObject:viewController];

View is not rotating

I am making a navigation based app and I need only portrait orientation except in a ZoomPictureViewController ( Zoom in, zoom out images) that supports all orientations.
I am presenting ZoomPictureViewController and returning YES in shouldAutorotateToInterfaceOrientation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
But I get no rotation. I know that shouldAutorotateToInterfaceOrientation, willRotateToInterfaceOrientation, RotateToInterfaceOrientation are only get called on the current/visible view controller but this is not happening in my case. I have checked it via putting breakpoints and NSLog.
Are you using any type of Navigation Controller or a Tab View Controller? I've noticed that there are issues when rotating a UIView that's not the first or only view as a direct child of the main window.
So if your UIView is part of a Navigation Controller or a Tab View Controller, you'll also need to override shouldAutoRotateToInterfaceOrientation on the Navigation Controller or Tab View Controller.
Also I here's an important gotcha in the Apple documentation that might explain the problem you are having.
Tab bar controllers support a portrait
orientation by default and do not
rotate to a landscape orientation
unless all of the root view
controllers support such an
orientation. When a device orientation
change occurs, the tab bar controller
queries its array of view controllers.
If any one of them does not support
the orientation, the tab bar
controller does not change its
orientation.

hide/show Scrollview in Navigation Controller

I am using a Navigation Controller. On top of the AppDelegate window I added a view that contains a scrollview and toolbar that I want to be using throughout the app. They appear fine on all the view controllers that I am using in the navigation controller. Now I would like to be able to hide and show them from each view controller.
I can't figure out how that should work,
any suggestions?
I am not sure if I understand you correctly but if you just want to hide/show scrollbars in each viewcontroller just call:
myScrollView.showsVerticalScrollIndicator = NO;
myScrollView.showsVerticalScrollIndicator = NO;
in init, viewDidLoad or any custom method in your UIViewController subclasses.

iphone navigation controller - transition between portrait and landscape view controllers

In my iphone app, i've two view controllers. First one is a portrait and second one is landscape.
When app is started, it will show the portrait view. On click of a button in portrait view, the view transitions to landscape view. Here, i'm using navigation controller.
If both the views are portrait, pushing the next view via navigation controller won't be a problem. How can I achieve transition between portrait and landscape views using nav controller.
Note that status bar is visible and nav bar is hidden.
I would suggest you to use the following instead of pushViewController
[self presentModalViewController:aController animated:YES];
This is the only solution i guess. If you are navigating further from the LandScape mode put the aController inside the UINavigationController and Present the NavController the same way as shown above.

How to prevent the view controllers in a tab bar controller from rotating?

I have a tab bar controller managing 4 tabs. I have subclassed the tab bar controller so that the shouldAutorotateToInterfaceOrientation: method only allows a specific view controller in one of the tabs to rotate. Everything works almost fine: the controllers in the remaining tabs do not rotate. However, when the view controller which is allowed to rotate actually rotates, if the user taps one of the remaining tabs, the corresponding view controller also appear rotated (even though its shouldAutorotateToInterfaceOrientation: method explicitly returns NO).
How do I prevent this from happening?
To be clear, here is an example. Tapping on the tabs 0,1, or 2 and trying to rotate the device, nothing happens (correctly). Tapping on the tab 4 and rotating the device, the view associated to the view controller of tab 4 is rotated (correctly). Now, still holding the iPhone in the rotated landscape orientation and tapping another tab (0,1, or 2) reveal a rotated view (which is not correct and what I am trying to avoid).
This is a commonly reported "bug" - however a good workaround is to force the shouldAutorotateToInterfaceOrientation: selector to be triggered as follows:
- (void)viewDidAppear:(BOOL)animated {
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[window addSubview:view];
}