我正在写一个应用程序,我想只在横向模式下查看。我已经对它进行了设置,如果iPhone处于纵向模式,则不会发生任何事情,并且当前图像仍处于横向模式。iPhone模拟器在横向模式下启动,主页按钮在右侧。如果将iPhone从一种横向模式旋转到另一种横向模式,则会发生动画并调整视图。但是,只要设备处于横向模式,并且主页按钮位于左侧,图像就会比所需的高出20像素,从而在屏幕底部显示一条白线。
尽管对此进行了逻辑调整的所有尝试,例如
self.view.frame = CGRectMake (0,20, self.view.frame.size.width, self.view.frame.size.height)这并不能解决问题。我在我的计算中考虑了状态栏。
.xib文件在UIImageView的顶部包含一个UIView。这是我第一次实现这些方法,所以如果解决方案相对简单,我深表歉意。下面是用于实现横向模式视图的两个方法的代码。
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//set up interface to only be viewed in Landscape
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
return interfaceOrientation;
else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return interfaceOrientation;
else
return NO;
}
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)tointerfaceOrientation duration:(NSTimeInterval)duration {
if(UIInterfaceOrientationLandscapeRight){
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
else if (UIInterfaceOrientationLandscapeLeft) {
//shouldn't adjustment to 20 fix the view?
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
else return;
}发布于 2011-10-07 08:04:27
为了让UIViews正确地调整子视图,您必须查看UIView属性:autoresizingMask,并将掩码设置为自动调整所需内容的大小,如果这不起作用,您将不得不重写:
- (void)layoutSubviews参考资料:UIView reference
https://stackoverflow.com/questions/7681823
复制相似问题