我注意到我的设备和模拟器上的方向非常间歇.
我有一个我提供的模态视图控制器,这是我的应用程序中唯一支持旋转的东西.
如果我在不移动设备的情况下以纵向方式启动应用程序,请打开模态VC然后旋转设备,它通常可以正常工作.但是,有时如果我打开横向拿着设备的应用程序,然后旋转到纵向,启动VC然后旋转设备,不会发生旋转.看起来很间歇.有时,如果我以纵向模式启动应用程序然后打开VC并旋转设备,则没有任何反应,直到我退出并重新启动它,应用程序中才会出现方向.
这很奇怪,因为50%的时间它都有效!每当我通过Xcode启动它并在shouldAutorotateToInterfaceOrientation中设置断点时,它总能工作!
有没有人有这个或知道发生了什么?
Leo*_*Leo -1
即使您尝试以横向方式启动应用程序,您的手机也会以纵向方式启动它,然后根据手机所在的位置进入横向状态。
我不知道您使用什么代码来完成此任务。下面是摘自 Apple 代码片段的一段代码。看看这是否有帮助。
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)
interfaceOrientation duration:(NSTimeInterval)duration {
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
self.view = self.portrait;
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0);
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformIdentity;
self.view.transform =
CGAffineTransformMakeRotation(degreesToRadian(90));
self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
482 次 |
| 最近记录: |