UIActivityIndi​​catorView 在 TransitionWithView 中出现后没有动画

发布于 2024-12-29 15:50:28 字数 730 浏览 1 评论 0原文

我的主视图有一个子视图,其中有一个 UIActivityIndi​​catorView 。最初,该子视图的 hidden 属性设置为 YES

我希望这个子视图淡入屏幕上。我使用以下代码来实现此目的:

[UIView transitionWithView:self.view
                  duration:3.0
                   options:(UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                animations:^{
                    self.subviewWithActivitySpinnerInIt.hidden = NO;
                }

尽管活动指示器设置为动画,但在使用上述代码出现后它不会动画。但是,如果我将上面的代码替换为下面的行(在完全相同的位置),那么当活动指示器出现时,它就会出现动画。

self.subviewWithActivitySpinnerInIt.hidden = NO;

知道发生了什么事吗?

(使用 Xcode 4.2 和 iOS 5。)

There is a subview of my main view, with a UIActivityIndicatorView in it. Initially the hidden property of this subview is set to YES.

I want this subview to fade onto the screen. I have used the following code to achieve this:

[UIView transitionWithView:self.view
                  duration:3.0
                   options:(UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                animations:^{
                    self.subviewWithActivitySpinnerInIt.hidden = NO;
                }

Even though the activity indicator is set to animating, it doesn't animate after appearing with the above code. However if I replace the code above with the line below - in the exact same spot - then when the activity indicator appears it is animating.

self.subviewWithActivitySpinnerInIt.hidden = NO;

Any idea what's going on?

(Using Xcode 4.2 and iOS 5.)

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

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

发布评论

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

评论(1

猫瑾少女 2025-01-05 15:50:28

您是否尝试过将代码添加到完成块中?问题中缺少完成参数。

[UIView transitionWithView:self.view
                  duration:3.0
                   options:(UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                animations:^{ self.subviewWithActivitySpinnerInIt.hidden = NO; }
                completion:^{ self.subviewWithActivitySpinnerInIt.hidden = NO; }];

作为替代方案,尽管它可能不适合您的需求,但您可能需要考虑使用 animateWithDuration 而不是transitionWithView。我认为下面的代码是等效的:

[UIView animateWithDuration:3.0
                      delay:nil
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
                     self.subviewWithActivitySpinnerInIt.alpha = 1.0;
                 }
                 completion:nil ];

Have you tried also adding the code to the completion block? The completion parameter is missing in the question.

[UIView transitionWithView:self.view
                  duration:3.0
                   options:(UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction)
                animations:^{ self.subviewWithActivitySpinnerInIt.hidden = NO; }
                completion:^{ self.subviewWithActivitySpinnerInIt.hidden = NO; }];

As an alternative, though it may not be suited to your needs, you might want to consider using animateWithDuration instead of transitionWithView. I think the code below is equivalent:

[UIView animateWithDuration:3.0
                      delay:nil
                    options:UIViewAnimationOptionCurveLinear
                 animations:^{
                     self.subviewWithActivitySpinnerInIt.alpha = 1.0;
                 }
                 completion:nil ];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文