iPhone:屏幕旋转然后应用程序崩溃

iPhone:屏幕旋转然后应用程序崩溃,iphone,orientation,duration,Iphone,Orientation,Duration,我想得到一个即时屏幕的旋转方向时,它。在我的ViewController中,有一个UIImage和一个UILabel。我的工作如下: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } - (void)wil

我想得到一个即时屏幕的旋转方向时,它。在我的ViewController中,有一个UIImage和一个UILabel。我的工作如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];
}
没有line应用程序不会崩溃:

[self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];
当代码行试图将持续时间设置为零时,应用程序在旋转结束后立即崩溃

知道我做错了什么吗


谢谢。

您正在创建一个无限循环:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
  [self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];
  }

您正在从内部调用相同的函数。你的目标是什么?

你正在堆积许多WillRotateToInterface定向:持续时间:一个接一个的呼叫。 实际上,第一次调用该方法时,它会一次又一次地调用它,。。。直到崩溃。 放置持续时间:0意味着什么,事实上,用于旋转效果的CoreAnimation计时是在运行循环线程以外的单独线程上运行的,因此不能以这种方式停止堆栈调用。 应用程序在旋转后崩溃的原因可能是,当堆栈被填满时,动画已经开始(单独的线程)


只需禁用自动旋转并观察UIDeviceOrientationIDChangeNotification通知,然后应用适当的视图变换,即可获得即时方向。

我正在尝试避免屏幕旋转时出现动画。因此,我尝试将持续时间设置为0。但正如您所指出的,这是一个无限循环,有没有任何方法可以在持续时间=0的情况下调用willRotateToInterfaceOrientation方法?