因此,我正在研究一個提醒用戶平移對象而不是點擊它的選擇器。 以下代碼是動畫:在Swift中獲取UITapGestureRecognizer的發件人
func labelTapped(sender:UITapGestureRecognizer)->Void{
UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
sender.view.frame = CGRectMake(sender.view.frame.origin.x + 15, sender.view.frame.origin.y, sender.view.frame.width, sender.view.frame.height)
}, completion:
{(value:Bool) in
UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: {
sender.view.frame = CGRectMake(sender.view.frame.origin.x - 15, sender.view.frame.origin.y, sender.view.frame.width, sender.view.frame.height)
}, completion:
{(value:Bool) in
})
})
}
現在回到對象本身。我分配UITapGestureRecognizer
並將其添加到該對象,但我不能肯定它是如何工作的,因爲早在Objective-C中,我們用來做:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTapped)];
這裏不需要參數。但是在斯威夫特,我得把一個參數在括號labelTapped
後,因爲它會給我一個Missing argument for parameter #1 in call
錯誤:
let labelTap1=UITapGestureRecognizer(target: self, action: labelTapped())
我應該如何去有關解決此問題?謝謝!
你搖滾!謝謝。 –