I'm adding a subview to the UiView of my mainviewcontroller, that is presented in a similar way as a UIModalViewController with the Formsheet-style. (so it doesn't fill teh whole screen)
No if the device rotates the subview somehow gets resized to fill the whole mainview...
Even if I manually set:
subViewCtrl.view.autoresizingMask = UIViewAutoresizingNone;
it still autoresizes.
Why can't it simple stay in the middle as any other subview would?
Ok, I figured it out myself.
I accidentally did
[self.view.superview addSubview:rowCtrl.view];
so I changed this too
[self.view addSubview:rowCtrl.view];
and it worked as intended. Thanks anyway!
Of course, then one also has to set
rowCtrl.view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
otherwise it doesn't get centered properly when the interface rotates.
Is the view resizing, or is the view staying the same size while the dimensions of the screen change? You may want UIViewAutoresizingFlexibleWidth and/or UIViewResizingFlexibleHeight. If you use those values then your subview will resize to remain a constant distance from the edges of the screen; your view will change sizes, but remain centered.
Related
I have UIActivityIndicatorView centered horizontally in a XIB.
In iOS 4 (Simulator), the indicator defaults to Large White (the color property being introduced in iOS 5), which is fine. The weird part is that it is also offset.
My initial assumption was that something was wrong with the XIB (or something to that effect). However, in iOS 5 (Simulator, iPhone 4), it works perfectly.
Seeing as how the only thing changed from iOS 4 to iOS 5 regarding UIActivityIndicatorViews was the addition of the color property, I'm stumped. I'm aware that there's probably nowhere near enough information here to deduce the exact problem. I'm more concerned about where to start debugging, and welcome any suggestions as to what further information I could supply.
Further Information:
The iPad loads the indicator in a reliable position, only changing colors between iOS 4 and iOS 5.
I have two static origin points (portPoint = (x, y); landPoint = (w, z);), that I manually set on rotation. When the app loads, the indicator's origin is (correctly) portPoint (which I've verified via NSLog), despite being visually misaligned. When I rotate to landscape, the origin correctly (visually and data-wise) sets to landPoint. When I rotate back, the origin correctly (visually and data-wise) sets to portPoint, thus resolving the issue.
You're right that w/o seeing your code I can't tell if anything else is going on but centering a view within a superview and maintaining that when the device rotates is fairly simple. Try this:
Make sure the autoResizingMask of the UIActivityIndicatorView is set to UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
Position the activity indicator in the center of its superview, either in the XIB file or in viewDidLoad
Don't change the frame of the activity indicator on rotation, it should stay centered automatically
If the above doesn't fix it, post some code along with the autoResizingMask and contentMode values for relevant views.
It sure looks like its positioned as if the device were in landscape. Check to see that you reposition it properly when the view size or orientation changes.
Ideas:
1/ Your view (activity indicator superview) is bigger than your display (bad autoresizing mask? bad values in xib plist?) or it has bad position inside its superview.
2/ Autoresizing masks are not set correctly. For the activity indicator it should be
(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin)
To debug this, try to put logging into viewDidAppear. Get the center (CGPoint) of your activity indicator and use UIView methods to convert it to your top view coordinates (e.g. [UIView convertPoint:fromView:]). This position should be the same as the one you see on the screen.
If it's not, there is some bigger problem, possibly connected with animation states.
Otherwise you should be able to find the view which translates your activity indicator to this weird position. Log the frames of all views in your hierarchy.
Check that you log the information at the right place and you don't change view positions after the logging.
I have all my subviews set up so that they are based on self.view.
EG: UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,(self.view.frame.size.width-20),(self.view.frame.size.height-90))];
however when the view rotates (shouldRotateToDeviceOrientation or whatever) the views all stay the same size. How can I make them change shape to fit? Can I do this automatically?
Thanks
Absolutely. Take a look at the autoresizingMask property. If you set your image view, in this case, to have an autoresizing mask of UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight, then when its parent view resizes (as it may or may not automatically do when your app rotates—you might have to set a similar autoresizingMask on the parent view), it'll maintain the exterior margins you set up for it.
Just in case you have a view in the bottom of parent view this should help:
self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
Where self is your child view, that should be resized. If you do not set UIViewAutoresizingFlexibleTopMargin, then in horizontal mode you will not see your view, if it was in the bottom in vertical mode.
Also do not forget to set:
self.autoresizesSubviews = YES;
And autoresizing modes for all child view in your view. So that when it is resized, everything inside it also gets resized.
you have to [view setAutoresizingMask:...]
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:.
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.
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.