【发布时间】:2011-10-07 00:00:35
【问题描述】:
我正在编写一个我只想在横向模式下查看的应用程序。我已经进行了设置,如果 iPhone 处于纵向模式,则不会发生任何事情,并且当前图像仍处于横向模式。 iPhone 模拟器以横向模式启动,主页按钮位于右侧。如果 iPhone 从一种横向模式旋转到另一种,则会出现动画并调整视图。但是,只要设备处于横向模式且主页按钮位于左侧,图像就会比所需的高 20 像素,从而在屏幕底部显示一条白线。
尽管所有尝试在逻辑上调整这一点,例如
self.view.frame = CGRectMake (0,20, self.view.frame.size.width, self.view.frame.size.height)
它不能解决问题。我在计算中考虑了状态栏。
.xib 文件在UIView 之上包含一个UIImageView。这是我实施这些方法的第一次体验,所以如果解决方案相对简单,我深表歉意。下面是用于实现横向模式视图的两种方法的代码。
-(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;
}
【问题讨论】:
标签: iphone objective-c ios ipad xcode4