iPhone:更改 CATransition 会导致 UIActivityIndi​​catorView 停止动画

发布于 2024-12-22 18:28:04 字数 598 浏览 2 评论 0原文

当新视图推送到屏幕上时,我已经实现了非默认动画(请参见下面的代码)。由于某种原因,一旦我实现了这段代码,它就会导致我的 UIActivityIndi​​catorViews 停止工作。即使它们的 isAnimating 为 true,它们也会显示在屏幕上,但不会产生动画。我认为这是因为我更改了 CATransition,但无法弄清楚如何修复 UIActivityIndi​​catorView。

更改推送的默认动画

CATransition* fade = [CATransition animation];
fade.duration = 1.0;
fade.type = kCATransitionFade;
fade.subtype = kCATransitionFromTop;

[self.navigationController.view.layer 
addAnimation:fade forKey:kCATransition];

稍后在 viewDidLoad 中

[spinner startAnimating];

我开始动画,但微调器将显示但不动画。由于某种原因,我的第一个旋转器有动画,但之后就没有了。

I have implemented a non-default animation for when a new view is pushed onto the screen (see code below). For some reason once I implemented this code it caused my UIActivityIndicatorViews to stop working. They will been shown on the screen but not animate even when their isAnimating is true. I figure it is because of me changing the CATransition, but can't figure out how to fix it for the UIActivityIndicatorView.

change default animation for push

CATransition* fade = [CATransition animation];
fade.duration = 1.0;
fade.type = kCATransitionFade;
fade.subtype = kCATransitionFromTop;

[self.navigationController.view.layer 
addAnimation:fade forKey:kCATransition];

later on in viewDidLoad I start the animation

[spinner startAnimating];

but the spinner will show and not animate. For some reason the very first spinner I have animates but after that nothing.

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

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

发布评论

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

评论(2

谁把谁当真 2024-12-29 18:28:04

当我在 UINavigationController 的子类中使用 CATransition 来在推送或弹出视图控制器时具有自定义动画时,我遇到了这个问题。

在这个 UINavigationController 的子类的方法中,我有这样的代码:

- (void)addCustomTransition
{
    CATransition* transition = [CATransition animation];
    transition.duration = kAnimationDuration;
    transition.timingFunction =
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.view.layer addAnimation:transition forKey:nil];
}

但是,我后来发现你还必须将相同的动画添加到推送/弹出的 viewController 的视图层:

- (void)addCustomTransitionToViewController:(UIViewController *)viewController
{
    CATransition* transition = [CATransition animation];
    transition.duration = kAnimationDuration;
    transition.timingFunction =
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.view.layer addAnimation:transition forKey:nil];
    [viewController.view.layer addAnimation:transition forKey:nil]; // this is what was missing
}

这个推送/弹出的视图控制器的视图是具有 UIActivityIndi​​catorView 的视图没有正确设置动画。

希望这有帮助!

I was encountering this problem when using a CATransition inside a subclass of UINavigationController to have a custom animation when pushing or popping view controllers.

Inside a method of this UINavigationController's subclass I had this code:

- (void)addCustomTransition
{
    CATransition* transition = [CATransition animation];
    transition.duration = kAnimationDuration;
    transition.timingFunction =
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.view.layer addAnimation:transition forKey:nil];
}

However, I later found out you also have to add the same animation to the pushed/popped viewController's view's layer:

- (void)addCustomTransitionToViewController:(UIViewController *)viewController
{
    CATransition* transition = [CATransition animation];
    transition.duration = kAnimationDuration;
    transition.timingFunction =
    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = kCATransitionFade;
    [self.view.layer addAnimation:transition forKey:nil];
    [viewController.view.layer addAnimation:transition forKey:nil]; // this is what was missing
}

This pushed/popped view controller's view is that one that had an UIActivityIndicatorView that wasn't animating properly.

Hope this helps!

梦中楼上月下 2024-12-29 18:28:04

只需将持续时间从 1.0 更改为 0.3 或更少
只是我经过测试并且它正在工作

just change your time duration from 1.0 to 0.3 or less
just i am tested and it's working

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