2014-07-11 44 views
-1

我正試圖在Swift中使用animateWithDuration關閉。我已經在Apple的Book for Swift中提到了關閉中的參數。但是,我仍然收到錯誤。如何聲明Swift C關閉

下面的代碼片段:

if(!isRotating){ 
isRotating = true 

var myImageTemp :UIImageView = self.myImage 
UIView.animateWithDuration(0.5, delay: 1, options: UIViewAnimationCurve.EaseOut, animations: 
{ 
() in myImageTemp.transform = CGAffineTransformMakeRotation(angle + M_PI_2) 
}, 
completion: 
{ 
(Bool finished) in self.pathAnimation() }) 

}   

它給了我一個錯誤:

Could find an overload that accepts the supplied arguments.

並且還告訴我:

Implicit use of self in closure.

任何人可以幫助我嗎?

+0

你的代碼和問題的格式有點混亂。請整理它 - 這會讓人們更容易幫助你。 – ColinE

+0

可能重複[Blocks on Swift(animateWithDuration:animations:completion:)](http://stackoverflow.com/questions/24071334/blocks-on-swift-animatewithdurationanimationscompletion) – Pascal

回答

1

試試看:

UIView.animateWithDuration(0.2, 
    animations: 
    { 
     // your code. 
    }, 
    completion: 
    { 
     (completed: Bool) in 
     // your code. 
    }) 

(completed: Bool) in部分指示閉合需要標記completed一個布爾參數。如果您不想訪問completed參數,則可以使用下劃線將其忽略。

UIView.animateWithDuration(0.2, 
animations: 
    { 
     // your code. 
    }, 
    completion: 
    { _ in 
     // your code. 
    }) 
+0

仍然無法正確實施。仍然給我一個錯誤: 無法找到接受這些參數的animateWithDuration的重載。 –