OGeek|极客世界-中国程序员成长平台

标题: ios - View 被截断(横向与纵向) [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:17
标题: ios - View 被截断(横向与纵向)

我无数次遇到这个问题,不知道如何解决它。我在一个 Xcode 项目中工作(空项目 - 没有 XIB 的!)。我将方向设置为横向:

enter image description here

但这种情况一直在发生:

enter image description here

View 正在被截断。无论我做什么,它似乎都没有设置为正确的大小。由于某种原因,它使用纵向边界以横向显示 View 。有谁知道如何解决这一问题?我还想将方向限制为仅限横向。

更新 如果我将 1024 硬编码为宽度并将 768 硬编码为高度,则 View 不会被截断。这显然是一个糟糕的解决方案,但我无法弄清楚。有没有人知道解决方案?



Best Answer-推荐答案


检查您在应用委托(delegate)类的 application:didFinishLaunchingWithOptions: 中设置的 rooViewController。确保您在此 View Controller 类中返回正确的允许方向,您将其对象设置为 rootViewController:

- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationLandscapeRight;
}

- (BOOL) shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

在您的应用委托(delegate)中添加此功能:

- (NSUInteger) applicationUIApplication *)application supportedInterfaceOrientationsForWindowUIWindow *)window{ 

 return UIInterfaceOrientationMaskLandscape|UIInterfaceOrientationLandscapeRight; 
 }

关于ios - View 被截断(横向与纵向),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16765254/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4