ind*_*gie 21 iphone cocoa-touch ipad ios
在我的iPad应用程序中,我需要运行一些布局代码,以根据方向设置正确的布局.默认情况下,布局是针对横向方向配置的,因此在应用程序以纵向模式启动的情况下,我需要采取额外操作来正确配置视图以便以纵向显示.
在我的-application:didFinishLaunchingWithOptions:
方法中,我使用了检查方向[[UIDevice currentDevice] orientation]
.这里的问题是,即使应用程序在横向启动,它也始终返回纵向.有没有办法解决?
Ano*_*mie 36
这是预期的行为.请参阅UIViewController文档:
注意:在启动时,应用程序应始终以纵向方式设置其界面.该后
application:didFinishLaunchingWithOptions:
方法返回时,应用程序使用上述的意见到适当的取向显示窗口之前旋转视图控制器旋转机构.
换句话说,就设备而言,在应用程序启动时,方向是纵向.在application:didFinishLaunchingWithOptions:
它之后的某个时刻它会检测到不同的方向并调用你的shouldAutorotateToInterfaceOrientation:
方法,然后你的其他视图旋转方法,你应该正常处理.
Dil*_*lon 19
这是检查发布方向的最佳方法.首先,在AppDelegate中创建一个检查方向的新方法:
-(void)checkLaunchOrientation:(id)sender{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
BOOL isLandscape = UIDeviceOrientationIsLandscape(self.viewController.interfaceOrientation);
if (UIInterfaceOrientationIsLandscape(orientation) || isLandscape) {
//do stuff here
}
}
Run Code Online (Sandbox Code Playgroud)
在运行结束时-application:didFinishLaunchingWithOptions:
[self performSelectorOnMainThread:@selector(checkLaunchOrientation:) withObject:nil waitUntilDone:NO];
Run Code Online (Sandbox Code Playgroud)
Tyl*_*ler 13
使用self.interfaceOrientation
您的视图控制器-它的属性UIViewController
是由iOS版为您设置,在某些情况下比更可靠[[UIDevice currentDevice] orientation]
.
以下是详细说明:http://bynomial.com/blog/?p = 25
归档时间: |
|
查看次数: |
9611 次 |
最近记录: |