I have iPad application which uses iOS7 SDK with auto-layout.
my main view have a sub view which is a UITabBarController which programmatically creates it's view controller's (storyboard.instaniateViewController..).
Inside the views - when i'm in portrait mode - everything is fine. but when i move to landscape mode - the view's width is changed correctly, but the view's height remains as in Portrait mode.
The result is that my screen is truncated in a height.
Any ideas why it happens? constrains seems fine.
I can change it by programmatically change the vie's frame, but it doesn't seem right.
Thanks
OK, i see what the problem was - somewhere up the view's hierarchy was defined:
[viewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth]
and that meant that the height was not flexible of course. the fix is easy once i saw it:
[viewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight]
Related
Recently I ran into an issue with my app when changing the device's orientation.
This is my main ViewController (let's call it VC1) in portrait mode:
Now if you push / present any viewcontroller (let's call that VC2), rotate the screen while in VC2, and return back to the previous view (VC1), this is what I get:
Why doesn't VC1 rotate correctly like it should? This issue happens throughout the whole app and with any two views. I honestly have no idea what might be causing this or where to look, so any help would be appreciated.
Do you use constraints and autolayout? Can you post a screeen where constraints of the view are visible? I think there are some missing constraints
your navigation bar is properly resize in portrait and landscape mode So The main problem is you didn't add trailing Constraints to your view.
Just Add you trailing constraints on your view in Storyboard.
I have a problem that is bugging me like hell. I have a custom view on top of my apps main view for settings configuration. The background of this view uses a UIVisualEffectView. However, my app supports both Portrait and Landscape mode and when changing the orientation, the auto-resizing doesn't work properly for the blur effect.
This is what I mean, changing orientation in the simulator with slow animation set to on (look at whats happens in the bottom of the view):
https://www.dropbox.com/s/bgtx8ygdawkx8be/BlurProblem.mov?dl=0
I have tried setting different content modes and resetting the auto-resizing value, but nothing seems to help.
How can I get the UIVisualEffectView to resize correctly?
Try and set the frame in your viewDidLayoutSubviewsmethod. That way your frame gets set after your view is in place.
My app supports both portrait and landscape mode. I have a TableViewController that has some issues when i rotate from portrait mode to landscape mode. I want subviews of TableView not to change neither orientation nor size. But i cannot find the way. I tried from storyboard to uncheck Autoresize subviews but it did not work. My TableView is into a TabBarController. It is strange, that in another ViewController i have a similar TableView with exactly the same attributes that works fine. So i added some pics with the problem and with what i want.
The only code that handles TableView orientation changes is in viewDidLoadMethod the below:
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
The first image is from Portrait mode
The second from troublesome Landscape mode
And the third from the right TableViewController and the result that i want
Any advice would be helpful.
What you can do is setting a constraint on your imageView and force the width and height to stay fixed.
The issue was in size inspector. I had to keep autoresizing of ImageView only TopLeft.
This is a view controller than is modally presented and therefore full screen.
In the storyboard, the "top layout guide" is at y:64. That is what I would expect when the status bar is height:20 and navigation bar is height:44.
However, when the app runs, the "top layout guide" is y:52. I have no idea how or why it's losing 12 points.
When you use Apple's Navigation controller which inserts a navigation bar, it will have different heights based on your orientation. For example, the navigation bar is 44 points in portrait and 32 points in landscape. In your case, I'm guessing when your app runs, it is in landscape, thus the "top layout guide" is y:52 (32+20).
See this related post: NavigationBar with rotation.
If you are trying to monitor these navigation bar height changes for example like this:
-(void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
}
You will realize that, although app changed orientation to landscape mode, navBarHeight's value is still the old one (44).
To tackle this, use intrinsic size instead:
-(void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
CGFloat navBarHeight = self.navigationController.navigationBar.intrinsicContentSize.height;
}
In general, you can't be sure that the geometries of objects in storyboard (or a nib) will be the final on-screen geometries. The final on-screen geometries will depend upon not only device orientation, but also the screen dimensions (e.g., 3.5-inch vs. 4-inch iPhone).
Unfortunately, it's easy to think otherwise. For example, if storyboard is simulating the 4-inch iPhone in portrait and you run the app in the 4-inch Simulator in portrait, then the final on-screen geometries will be the same as those in storyboard.
To simulate different orientations or screen dimensions in storyboard, visit the view controller's Attributes inspector:
If you're using Xcode 5, there's also a "floating" button on the IB canvas in the bottom-right-hand corner that allows you to quickly change which form factor is simulated.
On iOS7, i have a viewController added as a subview to the root view controller like so:
[self.view insertSubview:self.tutorialViewController.view aboveSubview:self.accessoriesView];
What happens is in viewDidLoad and in viewDidAppear, it loads with landscape mode dimensions, instead of portrait.
This also happens on iOS6 and bellow, but somehow it gets resized so this is not an issue. It seems that self.view.frame is not always reliable: http://bynomial.com/blog/?p=85
What could be the cause of this and how can i fix it?