我正在将xCode 4用于我的项目,该项目应该适用于iPad和iPhone。所以,我创建了基于通用窗口的应用程序。我希望我的应用程序启动到横向模式,所以我添加以下内容 方法:
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
我设置interfaceOrientation == UIInterfaceOrientationLandscapeRight
并将密钥添加到application.plist:
Initial Interface Orientation
并将其设置为横向(右主页按钮)。
现在,应用程序确实以横向模式启动,但是,其中的每个组件(按钮,标签)都保持旋转90度(逆时针)。 当我加载xib时,Window orientation设置为Portrait并且下拉列表被禁用。 谁知道我做错了什么?
答案 0 :(得分:0)
shouldAutorotateToInterfaceOrientation
并不是要求你设置变量(即使你这样做也无法读取结果),这是一个关于指定方向是否可接受的查询。所以你想要:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) return YES;
return NO;
}
/* or: return interfaceOrientation == UIInterfaceOrientationLandscapeRight; */
XIB是一个单独的问题; Interface Builder及其Xcode 4中的替换部件都无法看到您在代码中所做的事情,因此他们不应该拒绝让您以横向模式进行设计。但是,它是链接到您想要设置方向的相关UIViewController的视图成员的视图,而不是窗口。