A toolbar is not where it should be
I have an iPhone app. i'm trying to make it universal w/out new xibs. from a UI aspect, my app is fairly simple and straight forward, i just have a a UIImageview and some toolbar开发者_高级运维s.
i'm having an issue where i set my top toolbar to 0, 0 but it is appearing in the middle of my screen when its an iPad.
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
i initially hide the toolbar and show it if you tap the screen (works properly on iPhone). when i try to set the toolbar hidden on the iPad, its in the middle of the screen. when i nslog the frame, it shows (0, -44, 320, 44) which means it still thinks the screen size is iphone of (480, 320).
the funny part is when i use my tap function to show/hide the toolbar, it behaves properly with a frame of (0, -44, 768, 44).
my hide/show animation block is:
[UIView animateWithDuration:.2
delay:0
options:(UIViewAnimationOptionAllowUserInteraction)
animations:^{
topToolBar.frame = CGRectMake(0, (-1 * topToolBar.frame.size.height), topToolBar.frame.size.width, topToolBar.frame.size.height);
}
completion:nil];
its the same code i use to try to initially hide the toolbar. any ideas what is going on?
I would guess it’s an issue with the toolbar’s autoresizing mask. If you’re creating it in Interface Builder, make sure that the strut on the bottom is grayed out and that the ones on the other three sides are highlighted, like this:
If you’re creating the toolbar programmatically, you can just set its autoresizingMask
to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
.
精彩评论