我有一个关于在标题提到的方法中快速实现的问题。如果我这样做:UIView.animateWithDuration完成
leadingSpaceConstraint.constant = 0
UIView.animateWithDuration(0.3, animations: {
self.view.layoutIfNeeded()
}, completion: { (complete: Bool) in
self.navigationController.returnToRootViewController(true)
})
我得到以下问题:在调用中缺少参数'延迟'的参数。这只会发生,如果我有完成部分self.navigationController.returnToRootViewController()。如果我将这个语句提取成这样一个单独的方法:
leadingSpaceConstraint.constant = 0
UIView.animateWithDuration(0.3, animations: {
self.view.layoutIfNeeded()
}, completion: { (complete: Bool) in
self.returnToRootViewController()
})
func returnToRootViewController() {
navigationController.popToRootViewControllerAnimated(true)
}
然后它完美地工作,完全按照我的要求。当然,这似乎不是理想的解决方案,更像是解决方法。任何人都可以告诉我我做错了什么,或者为什么Xcode(测试版6)这样做?
长期以来,这一直是问题的常见原因。它总是以不同的方式显示...在这里看到答案:http://stackoverflow.com/questions/24338842/what-am-i-doing-wrong-in-swift-for-calling-this-objective-c-block- api-call/24347498#24347498 – Jack 2014-08-31 20:49:58
[animateWithDuration:animations:completion:in Swift]的可能重复(http://stackoverflow.com/questions/24296023/animatewithdurationanimationscompletion-in-swift) – Jack 2014-08-31 20:50:58
Ha。我知道这是以前的答案,但没有找到这个骗局。 (其实,我很确定我已经在这个愚蠢的游戏之前回答了它,但是我在我的历史中也找不到它。) – rickster 2014-08-31 21:17:17