禁止在 iOS 中的启动视图上旋转
我有一个闪屏,我将 alpha 从 100 淡入到 0。我希望只有当 alpha 为 0 时,shouldAutorotateToInterfaceOrientation 才返回 YES。我无法让这段代码工作:
if ( splashView.alpha == 0 )
{
return YES;
} else {
return NO;
}
相反,splashView.alpha 总是返回 null。有什么想法吗?
I have a splash screen I fade the alpha on from 100 to 0. I want shouldAutorotateToInterfaceOrientation to return YES only when the alpha is 0. I cannot get this code to work:
if ( splashView.alpha == 0 )
{
return YES;
} else {
return NO;
}
Instead, splashView.alpha always returns null. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您将 alpha 设置为零时,转身并向视图询问其 alpha 将返回零。即使动画尚未完成(如果您想了解发生了什么,请了解核心动画中 modelLayer 和presentationLayer 之间的区别)。
为了得到你正在寻找的东西,这样的东西应该有效;
然后在您的
appDidFinishLaunching
方法(或任何有意义的地方)中执行以下操作;明智的说法,我是凭记忆输入的,因此它可能无法编译,如果您复制并粘贴,请阅读文档。
When you set the alpha to zero turning around and asking the view for its alpha will return zero. Even though the animation is not finished (the difference between the modelLayer and presentationLayer in Core Animation if you want to understand what's going on).
To get what you are looking for something like this should work;
Then in your
appDidFinishLaunching
method (or wherever makes sense) do something like this;Word to the wise, I've typed this from memory so it probably won't compile, if you copy and paste please go read the docs.
在动画期间,从 alpha 属性返回的值不一定与视图的瞬时 alpha 相匹配。此外,一旦 alpha 达到 0,就不能保证系统会重新检查shouldAutorotateToInterfaceOrientation:的结果,因此您的界面可能会陷入纵向状态,直到设备转动为止。
首先,考虑这是否真的是最好的计划。如果用户横向或倒置地握住设备,那么相对于他们的观看方式,横向或倒置显示启动屏幕真的是最佳体验吗?不过,如果您的“启动画面”与 Default.png 匹配,我可以在 iPhone 上看到它,因为它也始终以纵向模式显示。
但如果您必须这样做,更好的计划是让您的
willAnimateRotationToInterfaceOrientation:duration:
方法对启动屏幕视图应用反向旋转,以保持启动屏幕“直立”,无论方向如何应用程序的其余部分。请参阅将控件保持在横向模式但允许 uitabbar 切换< /a> 了解详细信息。During the animation, the value returned from the alpha property will not necessarily match the instantaneous alpha of the view. And further, once the alpha reaches 0 there is no guarantee that the system will re-check the result of
shouldAutorotateToInterfaceOrientation:
, so your interface may wind up stuck in portrait until the device is turned.First, consider whether this is really the best plan. If the user is holding the device in landscape or upside-down, is it really the best experience to display the splash screen sideways or upside-down with respect to how they're looking at it. Although I could see it on an iPhone if your "splash screen" matches Default.png, as that is always displayed in portrait mode too.
But if you must, a better plan would be for your
willAnimateRotationToInterfaceOrientation:duration:
method to apply a counter-rotation to the splash screen view, to keep the splash screen "upright" no matter what the orientation of the rest of the app. See Keeping controls in landscape mode but allowing uitabbar to switch for details.alpha 值应该在 1.0 和 0.0 之间,所以我猜这可能是你的问题。
The alpha value should be between 1.0 and 0.0, so I'm guessing that might be your problem.
您应该只使用块动画:
这将运行动画块,完成后,为您的方法返回 YES。
You should just use block animations:
This will run the animation block and once completed, return YES for your method.