So I'm working on a selector that reminds users to pan the object instead of tapping it. The following code is the animation:
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
})
})
}
now back to the object itself. I'm allocating a UITapGestureRecognizer
and adding it to the object, but i'm not so sure how it works, since back in Objective-C, we used to do:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTapped)];
where no parameter is needed. However in Swift, I'll have to put in a parameter in the parenthesis after labelTapped
, as it will give me a Missing argument for parameter #1 in call
error:
let labelTap1=UITapGestureRecognizer(target: self, action: labelTapped())
How should I go about resolving this issue? thanks!
The action selector is a String ending in colon, which tells it there is one parameter (the sender):
let labelTap1=UITapGestureRecognizer(target: self, action: "labelTapped:")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With