ios - Swift animateWithDuration Completion 在推送模态视图时运行?

标签 ios objective-c iphone swift core-animation

下面的代码为我的一个 View 设置了动画并有一个完成 block

UIView.animateWithDuration(0.5, delay: timeToShow, usingSpringWithDamping: 0.75, initialSpringVelocity: 2, options: nil, animations: {
                self.murmurComposeTextView.frame = oldFrame
                self.showNewMurmurView.frame = self.getLeavingBGFrame()
                }, completion: { finished in
                    self.pickerButtonBig.enabled = true
                    self.pickerButton.enabled = true
                    self.isShowingNewMurmur = false
                    self.murmurComposeTextView.becomeFirstResponder()
            })

如果我在运行时呈现模态视图,然后快速关闭它,我注意到两件事:

  1. 动画尚未完成,但照常进行(这是我想要的)。
  2. 完成 block 已经运行,因为启用了 pickerButton,self.murmurComposeTextView.becomeFirstResponder 已经运行,等等。这是我不想要的。

有谁知道这种行为是否是故意的,或者我是否有错误,以及是否有办法修复它?谢谢!

最佳答案

传递到完成 block 的“finished” bool 值指示调用完成 block 时动画是否实际完成。

所以你可以检查 Bool 来确定你想要做什么。像这样的东西:

UIView.animateWithDuration(0.5, delay: timeToShow, usingSpringWithDamping: 0.75, initialSpringVelocity: 2, options: nil, animations: {
            self.murmurComposeTextView.frame = oldFrame
            self.showNewMurmurView.frame = self.getLeavingBGFrame()
            }, completion: { finished in
               if (finished) {
                    self.pickerButtonBig.enabled = true
                    self.pickerButton.enabled = true
                    self.isShowingNewMurmur = false
                    self.murmurComposeTextView.becomeFirstResponder()
               } 
        })

文档: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/clm/UIView/animateWithDuration:animations:completion :

关于ios - Swift animateWithDuration Completion 在推送模态视图时运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27909933/

相关文章:

ios - 删除 UserDefaults 的简单方法(无需编码)

objective-c - 将 UITableViewController 添加到其他 View

ios - ON DELETE CASCADE 在 ios 中的 sqlite3 中不起作用

ios - PFQueryTableViewController 不加载图像 parse.com

ios - ios 模拟器中导航栏顶部的空白 View ?

ios - 如何在masterViewController中呈现modalViewController?

objective-c - React-native - 如何从 Objective-C 中的文件路径打开图像

ios - 如何在 Swift 中获取前置摄像头?

iphone - Objective-C:更改来自单独类的图像

Java:推送通知已发送但未收到