TableView Rotation resizes subviews - ios

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.

Related

UIView are not properly located in ViewController after Rotation

I have a navigation controller with viewcontroller with container view, where views are loaded programmatically and based on the button click subview is loaded on top of the view. When I add subview from same orientation the views are laid properly but when the subview is rotated while adding on view, the subview is not properly located where they are supposed. How can I fix this issue?
Thanks
you can use auto layout or/and size classes or implement didRotateFromInterfaceOrientation to detect the orientation of device whether it is in landscape or portrait mode and then change the position of your UIView accordingly
You should use of autolayout or size class. Use orientation method than you can set subview possition according them.

UIVisualEffectView changing bounds incorrectly on orientation change

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.

ios7 iPad wrong view size in Landscape mode

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]

If ViewController is embedded in TabBarController, some of the content is not tappable

I have a test project and created ViewController which is embedded in TabBarController. I've placed 'UISearchBar' and 'UISegmentedControl' with constraints and in portrait mode they are clickable. But when I rotate to landscape mode(iPhone) only 320 pixels of the searchBar and segmentedControl is clickable, the rest isn't. This is better explained in the figures below.
Why is this happening?
How should I "stretch" the clickable area in landscape mode?
As you can see the constraints are working fine, the components have their correct sizes.
Some of your constraints are working fine, but very likely others are not. If the segmented control is only partially tappable in landscape, you should check the frame sizes for it's superview(s).
It looks like in landscape mode the segmented control is partially outside the superview frame. If the superview frame is ok, look further into the superview hierarchy.
To fix it, try this:
Select all the components in IB (search bar + segmented control + date picker)
Open menu 'Editor' -> 'Resolve Auto Layout Issues' -> 'Reset to Suggested Constraints'
I've just put the following code in mine TabBarViewController class.
- (void)viewDidLayoutSubviews
{
// fix for iOS7 bug in UITabBarController
self.selectedViewController.view.superview.frame = self.view.bounds;
}

Prevent UITableViewCell.backgroundView From Resizing Image On Orientation Change

I have a table cell with a custom backgroundView which looks great while in portrait, however when I move to landscape the backgroundView gets stretched to match the landscape width. How can I make it so the backgroundView stays the same height/aspect ratio?
This seems to do nothing:
self.backgroundView.autoresizingMask = UIViewAutoresizingNone;
Is there a solution to this? Here's some screenshots to illustrate. The first image shows portrait view properly, the second shows landscape view with the middle rows scaled when I want them to be the same size as they were in portrait, just located in the middle (much like the images above them, which are actually just UIImagViews added directly to the cell, rather than changing the backgroundView property).
Thanks!
Figured this out. All I needed to do was set the contentMode.
backgroundView.contentMode = UIViewContentModeCenter;

Resources