UIViewController:识别方向正在进行中
我正在开发 iPhone 应用程序。 UIViewController
中是否有任何默认状态/访问器可以告诉方向是否正在进行中?
目前我已经完成了以下操作:
UIViewController
子类中的 BOOL
成员说 isOrientationChangeInProgress
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
isOrientationChangeInProgress = YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
isOrientationChangeInProgress = NO;
}
有没有更好的方法?
I'm developing an iPhone application. Is there any default state/accessor in UIViewController
that tells if orientation is in progress?
Currently I have done the following:
A BOOL
member in subclass of UIViewController
say isOrientationChangeInProgress
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
isOrientationChangeInProgress = YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
isOrientationChangeInProgress = NO;
}
Is there any better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 建议在
willRotateToInterfaceOrientation:duration:
中启动任何动画,因此在调用该方法后不久就会发生旋转。 uration 属性告诉您旋转完成后调用didRotateFromInterfaceOrientation:
需要多长时间,或者大约持续时间秒后。所以,我认为事后看来,你的 BOOL 是最好的选择。我不明白为什么你需要知道这一点;也许你想要的结果可以通过不同的方式实现。你想做什么?
Apple advises starting any animations in
willRotateToInterfaceOrientation:duration:
, so he rotation happens soon after that method is called. The duration property tells you how long it takesdidRotateFromInterfaceOrientation:
is called once the rotation is finished, or about duration seconds later.So, I suppose your BOOL is the best thing to to do in hindsight. I don't understand why you need to know this though; maybe your desired outcome can be achieved a different way. What are you trying to do?
您也可以要求告知设备方向信息:然后
您会在orientationChanged:发生更改时被告知
You can ask to be told device orientation information as well:
You then get told in orientationChanged: when the change happens