我想得到一个即时屏幕的旋转时,它的方向。在我的ViewController中有一个UIImage和一个UILabel。我的工作如下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];
}没有线应用程序就不会崩溃:
[self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];当代码行试图将持续时间设置为零时,应用程序在结束后立即崩溃。
知道我做错什么了吗?
谢谢。
发布于 2011-02-02 14:39:59
您正在堆叠许多自愿的willRotateToInterfaceOrientation:持续时间:一个接一个调用。实际上,当方法第一次被调用时,它会一次又一次地调用它,然后,.直到崩溃。放置持续时间:0没有任何意义,实际上,用于旋转效果的CoreAnimation计时是在一个单独的线程上运行的,而不是run循环线程,因此您不能以这种方式停止堆叠调用。应用程序在旋转后崩溃的原因可能是因为当堆栈被填充时,您的动画已经启动(单独的线程)。
您可以通过简单地禁用自动转换和观察UIDeviceOrientationDidChangeNotification通知来获得即时定位,然后应用适当的视图转换。
发布于 2011-02-02 14:38:20
您正在创建一个无限循环:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self willRotateToInterfaceOrientation:[self interfaceOrientation] duration:0];
}从内部调用相同的函数。你打算做什么?
https://stackoverflow.com/questions/4875492
复制相似问题