ipad: problem in landscape and portrait orientation - iphone

I am completely new to iPad development and facing this issue:
In added a View, "LoginView", as a subview of "detailView". I displays fine in portrait mode, but in landscape mode its getting shifted to lefthand side and covers only half of the screen.
Please help me and provide solutions for these two:
1) "LoginView" should cover the complete screen in landscape mode.
2) After LoginView, if login is successful I add 'SearchView' to 'LoginView' as subview, but this screen is hiding the toolbar(and thus toolbar button) in both the Portrait/Landscape I want that toolbar to be visible.
3) Again this 'SearchView' is shifted to left of the screen I want this to be on righthand side.

If you're using Interface Builder then open inspector and go to the size tab.
You can define how the view should resizing.
If you are programmatically designing your view then you can have define the autoresizing mask with:
// eg. of a possible combinaison
view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin;
/* With a possible combinaison of those value:
UIViewAutoresizingNone
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleWidth
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleHeight
UIViewAutoresizingFlexibleBottomMargin
*/

Check the views auto-resizing property

Related

I rotate screen manually to Landscape but the taskbar buttons dont use the new full width of 480, rather they only use the 320 portion of the bar

I rotate my screen to landscape mode
- (void)rotateScreen
{
[self.tabBarController.view setTransform:landscapeTransform];
self.tabBarController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.tabBarController.view.bounds = CGRectMake(0.0, 0.0, 480.0, 320.0);
self.tabBarController.view.center = CGPointMake (240.0, 160.0);
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
}
It all seems to work well,
The view and Navbar are rotated, the postion of the Tabbar changes position to the bottom of the screen.
The problem is that the buttons on the Tabbar do not use the full width of the screen rather they only use the space of 320pixles rather than growing onto the full width of the bar, which has become 480 pixels now.
Is there someway I can ask it to grow in width?
I have seen similar issues when the views you have added are added as subviews using the addSubView method instead of being pushed to the navigation bar.
That is the first thing I would review.
Did you anchor the tab bar to the right edge of the view? The anchors play an important role in sizing you view based on the parent.
Read about UIViewAutoResizingMask in developer documentation for more info.

Rotating the uiview without IB

In my app all my controls are created in code. I have not used IB for controls. now i want to rotate the view to landscape mode. I know I have to use the shouldAutorotate method for this purpose.
But since I have not used IB, how can I resize the controls when they are in landscape mode? How can I position them correctly using code only?
In most cases you can get views to resize themselves appropriately just by setting their autoresizingMask property to some combination of:
UIViewAutoresizingFlexibleLeftMargin
UIViewAutoresizingFlexibleRightMargin
UIViewAutoresizingFlexibleTopMargin
UIViewAutoresizingFlexibleBottomMargin
UIViewAutoresizingFlexibleWidth
UIViewAutoresizingFlexibleHeight
For example, let's say you want a view's width to increase when you rotate it to landscape, you want it to maintain the same margins relative to the top, left, and right sides of the screen, and you want its height to remain the same. This means that out of the six attributes above, only the width and bottom margin should be flexible. The other four attributes are fixed. So you would do:
yourView.autoresizingMask = UIViewAutoResizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
In those rare cases when you can't get the views to behave appropriately using their autoresizingMask property, you can wrap them in a custom view and override that view's layoutSubviews method. This method gets called when the view's frame changes due to autorotation, so you can check [[UIApplication sharedApplication] statusBarOrientation] and update the frames of your subviews manually.
You position them correctly using code the same way you likely positioned them in the original orientation, for example by setting their frame.
As for where in code to do this, check out the various orientation change methods of UIViewController that will be called when the device orientation changes. You could, for example, move/resize the controls in the view within willAnimateRotationToInterfaceOrientation:duration:.

Auto Resizing with Interface Builder and Code?

I want to use auto resizing mask in iPhone to adjust view in landscape and portrait mode. The problem is when I apply width spring from Interface builder, the button changes its size proportionally. But when I apply the same spring by code i.e.
[self.view setAutoresizesSubviews:YES];
[testButton setAutoresizingMask:UIViewAutoresizingNone];
[testButton setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
the button doesn't show the same behavior.
Auto resizing applied on button from Interface builder:
original button size: 120 width and 37 height
landscape mode button: changes size proportionally
Auto resizing applied on button from Code:
original button size: 120 width and 37 height
landscape mode button: changes size by keeping same left and right margins in both Portrait and landscape mode.
The mask applied from code doesn't seem to work correctly as the size of button created from code comes out to be greater.
My views are complex that is why i don't want to set the frames of each subview on the View.
Anyone with same issue!!!
Thnx for responding guys, by the way I have solved my issue. There was nothing to do with the link with the interface builder. Actually while creating your view without interface builder, if you want the subviews to be auto re-sized; You have to set springs and struts in a single line using the bitwise OR connector. The code I used for re-sizing my view is:
[appLogo setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin];
Check 2 things.
1. Connection of IBOutlet
2. Also check that you have created the #property of the IBOutlet of view you have created.
Hope this solve the issue.

IPhone how to properly resize view when rotating device

I have been trying to resize my view inside a view Controller with no luck so far. Basically I have a button at the very bottom of my view and when the orientation changes from Portrait to Landscape the button is no longer visible, because its just too far down now.
How can I resize this view so that when the orientation changes the button is still visible?. I have tried setting
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
and basically every other possible combination, with no luck so far. I know I can do this by manually repositioning the button, but is there a better way to do this?.
Thank you.
-Oscar
The view containing the button must be auto-resized using your mask (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight).
On the containing view autoresizesSubviews must be set to YES.
The button must use UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin.

View shows only half of width in landscape mode

I have one view controller,in that i have 1 UIButton ,when i click on that button one view opens ,but when i move it to landscape mode at that time the view shows only half of width not full.what should i do?????
Thanks and welcome for answers
You may need to set the autoresizing properties, i.e.
myView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
You should probably call setNeedsDisplay on the view after changing the orientation.