I setup in IB in portrait mode my main view (for iPad). I have a toolbar, a map view (x=0, y=44, w=768, h=774) and a footer view (x=0, y=818, w=768, h=186).
When I rotate the iPad, I want the map to stay on the left side and be resized vertically to fit the view (x=0, y=44, w=756, h=704) and put the footer view on the right side (x=0, y=818, w=768, h=186) and extend vertically too.
Anyway, the effect is exactly the same as the WeatherBug application. I don't know how they do that, but their view containing the information is rotating by 90 degrees with the UIScrollView and UIPageView, I have basically the same needs and really don't know how to make this. Do they have everything in the same xib? I'm so confused...
Please tell me if you know how to do/organize a such view!
Thank you...
If you want the map to stay against the left side and be able to resize vertically set its autoresizingMask as such: mapView.autoresizingMask = UIViewAutoresizingMaskFlexibleRightMargin | UIViewAutoresizingMaskFlexibleHeight;
I don't understand how you want to footerView to resize through (y=818 in landscape mode is out of the visible view).
You should read the UIView reference, specifically the part regarding autoresizing mask (link: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/autoresizingMask )
Related
I would like to have a view to the top or left of the device.
I have tried using a stack view to rotate the view but I was unable to use all interface orientations.
Example: the iPad orientation has a regular width and height in both portrait and landscape orientation. Thus I believe I cannot rotate the stack view axis on this device.
What are other options to keep the view how I want it preferably using the storyboard with auto-layout only but if needed using swift code.
Edit:
To clarify, both the blue and grey view can be seen as empty UIView for the purpose of this question.
To clarify, when you rotate the device, you want the text, buttons, etc to rotate but the background to stay the same (as in the view takes up the same screen area, but things in the view are rotated), correct?
If so, use size classes to give your views different constraints for different views
The initial root view controller is 9 (3x3) buttons with a custom background in portrait mode. When the device is rotated into landscape mode the last row of buttons (of course) are cut off and the background (which is 320x480) doesn't fill the width of the screen.
What is the proper way of handling this? Do I need to move and resize the buttons myself? Do I have multiple Nibs? How do I resize/rotate the background?
Use shouldAutorotateToInterfaceOrientation and/or deviceDidRotateSelector in your viewController to reposition / layout & scale your views programmatically as you require.
If you set the auto-resizing masks on the buttons to have flexible margins in all directions they should reposition themselves appropriately when you rotate the device. You can do this either in code, or in Interface Builder (which has a nice little simulator demonstrating the effect)
With regards the background, what I prefer to do is to make the image the combination of the maximum proportions of each orientation, and then center it. For instance, make your image 480 x 480, make the view that houses it the same size and then use the appropriate auto-resizing masks to achieve the desired effect.
First,I am sorry for my poor english...
So, i have a problem with a view which is added on a other one.
I am setting size of UIview in IB as 200px/200px
I set the center of this view with the center of parent view.
Everything is working great at this point.
I can see my View in the center of the parent view like i want.
Then I set the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
And that's working to.
But when i rotate the iphone, the size of the view change to full size, the view don't want to stay in center and go on the top left of the screen and resize as fullscreen...
Can somebody help me with this problem ?
Do I have to set the frame and the center after rotate ? That can't be automatic ?
Thank you!
In IB, under the "Autosizing" section, remove the "arrow" that indicates auto width/height of your component.
I'm having a nightmare with the rotation on iPad. I've searched all over the place for some tutorials, but nothing seems to really be for what I want. (Possibly not searching for the right thing?!)
I have a portrait view by default which is an image and a button inside the view. When I rotate, I detect this can work out if it's landscape. I then try to set the frame size of the uiview to fit nicely on the screen.
If I let it autoresize, it simply stretches and fills the screen. This I don't want.
but the trouble is, when I resize, the button gets resized too, but not in the same ratio as the image.
My question is: What's the best way to resize the view. I wanted to simply reduce the uiview by say 60% and it resizes EVERYTHING in that view with the same 60%. The only way I see this is working at the moment is to create two views... but that's twice the work and maintenance!
I've tried messing with the autosizing arrows in Interface builder, but that again seems to screw things up more!
I'm completely lost here!! Thanks for any info
The problem you have there is that the view is automatically resized to the screen ratio. On an iPad in Portrait Orientation the screen size is 1024x768. After the rotation to Landscape the origin rotates too and your screen content is skewed or stretched to 768x1024.
What you need to do is to override the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
message of the UIViewController of the view which rotates. This message is called within the animation block of the rotation. You just set the framesize of your subviews (the button) to whatever is best for you. Once i had a problem with rotating an OpenGL view. The content of the view was stretched when rotating to landscape. Since it is not possible to alter any OpenGL matrices within the animation block the only solution i found was to make the view quadratic and to set the origin behind the bounds of the screen (in -x direction). You have to override the message also to reset the origin above the screen (in -y direction) bounds in landscape mode, to keep the viewport in the middle of the screen. That way the view kept its ratio. Whatever solution is best for you, overriding this message should work out.
Have you tried disabling the autoresizesSubviews property on your UIView? It should prevent any size changes on the subviews when you resize your view.
In my iPhone app, I have a view (let's call it RectangleView) within the content view that I'd like to scale, along with all its subviews, when the iPhone is rotated. So, when the phone is rotated from landscape to portrait mode, I'd like RectangleView (and all its subviews) to keep their original shape and position relative to each other, but just get smaller. I am using autoresizing on it and all its subviews in Interface Builder to try and do this.
Now here's the problem. When the phone is rotated, all of RectangleView's subviews scale and move relative to the entire content view, not relative their parent view (which is RectangleView). This is a problem because the content view is now a different shape (portrait) than it was before (landscape), and so all the elements on the screen are in the wrong places, when they should just be scaled down within RectangleView. And I am confused because some of these elements even move out of RectangleView, which I didn't even know was possible since they are supposed to be contained within RectangleView.
Can anyone explain what might be happening here, and how I can just scale RectangleView and all its subviews to retain their original shape and positions, but just on a smaller scale? Thanks in advance!
Are you sure that they are moving out of the RectangleView, and it isn't that the RectangleView is resizing and filling the content area? Also, I'm not sure if it makes a difference, but I found that I needed to call [view setNeedsDisplay] after rotation to make my custom view work properly.