UIView 块动画与完成处理程序并将 UIViews 设置为隐藏

发布于 2024-10-17 13:25:41 字数 1063 浏览 7 评论 0原文

我热衷于 iOS 4 中的新块动画。也就是说,

  [UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionAllowUserInteraction  animations:^
        {
              someview.alpha = 0

        } completion::^(BOOL finished) 
             {
                 focusAndExposureBox.hidden = true;
           }];

我有一个使用手势识别器并在手势结束时对视图进行动画处理的语法。我有一个完成处理程序,它将某些视图设置为隐藏(出于性能原因,我需要这样做)。通常,由于设置了隐藏属性,交互会被阻止。我以前的解决方案是将以前的动画样式与animationDidStop 处理程序一起使用。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.25];
someview.alpha = 0;
[UIView commitAnimations];

但是,如果可能的话,我想使用较新的样式,因为它具有在动画完成后执行操作的更清晰的方法,并且是Apple 推荐的。所以,目前我正在使用这个黑客:

 [UIView animateWithDuration:1 delay:0 
      options:UIViewAnimationOptionAllowUserInteraction animations:^{

           someview.alpha = 0;

       } completion:^(BOOL finished) {


[someview performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:true] afterDelay:1];

            }];

有谁​​知道在这种情况下防止阻塞的方法吗?

I'm keen on the new block animations in iOS 4. That is, the syntax

  [UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionAllowUserInteraction  animations:^
        {
              someview.alpha = 0

        } completion::^(BOOL finished) 
             {
                 focusAndExposureBox.hidden = true;
           }];

I have a case where I am using gesture recognizers and animating a view at the end of a gesture. I have a completion handler which sets someview to hidden (for performance reasons I need to do this). Often interaction is blocked due to the hidden property being set. My previous solution is to use the previous style of animation with an animationDidStop handler

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.25];
someview.alpha = 0;
[UIView commitAnimations];

However, I'd like to use the newer style if possible, because it has a cleaner method of performing actions after the animation finishes, and is recommended by Apple. So, currently I am using this hackery:

 [UIView animateWithDuration:1 delay:0 
      options:UIViewAnimationOptionAllowUserInteraction animations:^{

           someview.alpha = 0;

       } completion:^(BOOL finished) {


[someview performSelector:@selector(setHidden:) withObject:[NSNumber numberWithBool:true] afterDelay:1];

            }];

Does anyone know of a way to prevent blocking in this case?

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

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

发布评论

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

评论(1

多情癖 2024-10-24 13:25:41

如果您将手势识别器与委托一起使用,您应该能够避免阻塞问题,因为委托函数将独立于主线程进行调用。

You should be able to avoid the Blocking issue if you're using Gesture Recognizers with delegates, as the delegate function will be invoked independent of the main thread.

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