jbr*_*nan 21 iphone cocoa-touch uikit ipad device-orientation
在横向模式下启动时,无法为我的iPad应用程序获取正确的界限.我在Info.plist文件中设置了正确的键,我的视图控制器在横向(和纵向,自然)中正确启动.
在我的applicationDidFinishLaunching:方法中,我在3秒延迟后调用选择器,并且该方法调用[[UIScreen mainScreen] applicationFrame],但它返回一个纵向框架(即高度>宽度).
有谁知道如何解决这一问题?它闻起来像是一个臭虫(如果是这样我将提交雷达),但如果它是预期的行为,它在哪里记录?
ben*_*ord 35
我从不依赖 [[UIScreen mainScreen] applicationFrame],特别是在应用程序发布期间.
在代码中创建视图时,使用superview设置框架.
如果你使用带有"模拟界面元素"的xib,它们的大小将正确,一切都会很好.
基于UINavigationController的应用程序
在基于UINavigationController的应用程序的情况下,直接从中抓取框架self.navigationController.view,不要尝试使用[self loadView]和self.view.superview.UINavigationController使用"隐藏"子视图来完成它的工作 - 因此直接超级视图将无法工作.
UINavigationController很特别,因为在应用程序启动期间,导航控制器loadView会在调用后调整视图大小.当你自动调整踢球时,你最终会在屏幕底部留下一小部分空间.
为什么不用UIScreen
[[UIScreen mainScreen] applicationFrame]无法可靠地工作(特别是在横向应用程序启动期间).我的经验是viewcontroller的interfaceOrientation属性与applicationFrame方向不匹配.
100*_*ams 14
CGRect bounds = [[UIScreen mainScreen] bounds]; // portrait bounds
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
bounds.size = CGSizeMake(bounds.size.height, bounds.size.width);
}
Run Code Online (Sandbox Code Playgroud)
这是我在视图控制器处于格局时获取正确CGRect的方式:
CGRect landscapeBounds;
if (self.view.frame.size.width < self.view.frame.size.height)
landscapeBounds = CGRectMake(self.view.frame.origin.y, self.view.frame.origin.x, self.view.frame.size.height, self.view.frame.size.width);
else
landscapeBounds = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
Run Code Online (Sandbox Code Playgroud)
这是设计的.您应该查询超级视图的大小并根据需要进行调整.
| 归档时间: |
|
| 查看次数: |
24590 次 |
| 最近记录: |