1

以下代码适用于我可以访问的所有设备模拟器。但是,一些用户报告了导致我认为在某些情况下没有调用完成块的问题。我现在不知道。有什么建议吗?

CATransaction.begin()
CATransaction.setCompletionBlock {
  self.performSegue(withIdentifier: "ContractViewController", sender: sender.companyJob)
}

self.navigationController?.popViewController(animated: true)
CATransaction.commit()

顺便说一句,我想要实现的是弹出和推送屏幕过渡动画。在这一点上,我愿意接受任何解决方案或解决方法。提前致谢。

来自doc的额外文件:

/* Accessors for the "completionBlock" per-thread transaction property.
 * Once set to a non-nil value the block is guaranteed to be called (on
 * the main thread) as soon as all animations subsequently added by
 * this transaction group have completed (or been removed). If no
 * animations are added before the current transaction group is
 * committed (or the completion block is set to a different value), the
 * block will be invoked immediately. Added in Mac OS X 10.6. */
4

1 回答 1

-1

如果您使用的是界面生成器,则可以使用 Unwind Segue 并创建一个带有完成块的自定义 UIStoryboardSegue,如下所示

class ViewController: UIViewController {
    @IBAction func unwind(_ segue: UIStoryboardSegue) {
        if let segue = segue as? StoryboardSegue {
            segue.completion = {
                // present or push in here
            }
        }
    }
}

class StoryboardSegue: UIStoryboardSegue {
    var completion: (() -> Void)?

    override func perform() {
        super.perform()
        self.destination.transitionCoordinator?.animate(alongsideTransition: { _ in

        }, completion: { _ in
             // do what you want after the animation is finished
           self.completion?()
        })
    }
}
于 2019-01-30T17:52:23.437 回答