Ios 为什么我的UIToolbar在旋转时改变宽度而不是高度?
我在iOS6中工作,当设备旋转时,我的UIToolbar的高度没有变薄,尽管它正在变宽以覆盖增加的长度。这是我的密码:Ios 为什么我的UIToolbar在旋转时改变宽度而不是高度?,ios,objective-c,rotation,Ios,Objective C,Rotation,我在iOS6中工作,当设备旋转时,我的UIToolbar的高度没有变薄,尽管它正在变宽以覆盖增加的长度。这是我的密码: -(void)loadToolBar:(NSString *)t { //Creates a toolbar. [bar removeFromSuperview]; if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) { bar = [[UIT
-(void)loadToolBar:(NSString *)t {
//Creates a toolbar.
[bar removeFromSuperview];
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 480, 32)];
}
else bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
bar.autoresizingMask=UIViewAutoresizingFlexibleWidth;
bar.autoresizingMask=UIViewAutoresizingFlexibleHeight;
bar.autoresizingMask=UIViewAutoresizingFlexibleBottomMargin;
}
我还从中添加了此方法,但似乎没有什么不同:
- (void) layoutForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Adjust the toolbar height depending on the screen orientation
CGSize toolbarSize = [bar sizeThatFits:self.view.bounds.size];
bar.frame = (CGRect){CGPointMake(0.f, CGRectGetHeight(self.view.bounds) - toolbarSize.height), toolbarSize};
webV.frame = (CGRect){CGPointZero, CGSizeMake(CGRectGetWidth(self.view.bounds), CGRectGetMinY(bar.frame))};
}
有没有想到我做错了什么?你有没有在
中调用布局进行界面定位:
将动画定位到界面定位:持续时间和视图将出现
?就是这样!非常感谢。这与您的问题无关,但可能会让您省去一些心痛:您正在使用UIDevice的方向属性,这可能会产生一些奇怪的结果,除了您预期的4个方向之外,还有UIDeviceOrientationFaceUp
和UIDeviceOrientationFaceDown
我会在您所在的UIViewController子类上使用属性interfaceOrientation
,因为这是一种ui接口定向
类型,它只有你关心的4个方向。谢谢你的提醒。我试试看。