使用 kCATransitionMoveIn 在 UIView 中滑动时出现故障

发布于 2024-10-10 12:22:35 字数 730 浏览 6 评论 0原文

我有一个 UINavigationController,当用户按下按钮时,其 UIView 会从屏幕底部滑入。

不过,在我将视图的“隐藏”属性设置为“否”后,UINavigationController 的视图有时会完全出现一帧,就好像动画已经完成一样。

这是显示/隐藏视图的代码:

- (void)showGUI: (bool)show
{
 CATransition *transition = [CATransition animation];
 transition.duration = 0.5;
 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

 if (!show)
 {
  transition.type = kCATransitionReveal;
  transition.subtype = kCATransitionFromBottom;
 }
 else 
 {
  transition.type = kCATransitionMoveIn;
  transition.subtype = kCATransitionFromTop;
 }

 [navController.view.superview.layer addAnimation:transition forKey:nil];

 navController.view.hidden = !show;
}

I have a UINavigationController whose UIView slides in from the bottom of the screen when the user presses a button.

Immediately after I set the view's "hidden" property to NO, though, the UINavigationController's view sometimes appears fully in place for one frame, as if the animation was finished already.

This is the code that shows/hides the view:

- (void)showGUI: (bool)show
{
 CATransition *transition = [CATransition animation];
 transition.duration = 0.5;
 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

 if (!show)
 {
  transition.type = kCATransitionReveal;
  transition.subtype = kCATransitionFromBottom;
 }
 else 
 {
  transition.type = kCATransitionMoveIn;
  transition.subtype = kCATransitionFromTop;
 }

 [navController.view.superview.layer addAnimation:transition forKey:nil];

 navController.view.hidden = !show;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素年丶 2024-10-17 12:22:35

当向添加动画的图层添加/删除图层时,将应用 CATransition 动画。如果切换隐藏属性不起作用,请尝试删除视图。

CATransition animations are applied when layers are added/removed from the layer you add the animation to. If toggling the hidden property doesn't work, then try removing the view instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文