swift - 锁定/解锁 UIView 动画完成 block 中代码的关键部分 - Swift

标签 swift

如何使用 Swift(在子类 UIView 中)锁定和解锁 UIView 动画完成 block 中的关键代码部分?

func MoveCard(sourcePile: Pile, destPile: Pile) {

    // Temporarily disable user interaction
    disableUserInteraction()

    // Move card from source pile to destination pile
    UIView.animateWithDuration(0.1) {
        () -> Void in

        // Move card center
        self.center = destPile.center

        // CRITICAL SECTION OF CODE
        // Add card to destination pile array
        destPile.cards.append(sourcePile.cards.last!)
        // Remove card from source pile array
        sourcePile.cards.removeLast()

        // Reenable user interaction
        enableUserInteraction()
    }
}    

最佳答案

试试这个:

UIView.animateWithDuration(0.1, animations: {
    // your animation code
}, completion: { (complete: Bool) in
    // your completion code
})

关于swift - 锁定/解锁 UIView 动画完成 block 中代码的关键部分 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31615481/

相关文章:

ios - 检查用户是否登录到 iCloud? swift/iOS

ios - 快速从类(class)中执行转场

swift - 在 tableView 中放置一个 UIButton

swift - 更新到 Xcode 8 beta 6 后,关联枚举中丢失了 CKErrorCode 和 .rawValue

ios - 使用 Swift 的 Twitter API 无效 URLRequestWithMethod

ios - AutoLayout 约束以适应矩形内的 View ,保留一定的纵横比(以编程方式)

ios - Swift - 循环中的完成处理程序

ios - Storyboard TableView 的 Realm 初始化

ios - 无法更改 Appdelegate 中的 rootViewController?

ios - Xcode 项目(从 gi​​thub 下载的 zip)构建,但我在模拟器中出现黑屏