uitapgesturerecognizer

Unrecognized selector with UITapGestureRecognizer

邮差的信 提交于 2019-12-02 08:41:11
I'm trying to add in my app the possibility to dismiss the keyboard when the user taps somewhere else out of the text fields. I'm implementing this functionality using UITapGestureRecognizer. I create a new UITapGestureRecognizer object using the Unrecognized selector with UITapGestureRecognizer(target: Any?, action: Selector?) and set the action parameter to a function that resigns the first responder of both the text fields I'm using in this view. I set everything properly adding the keyword @objc before the method I pass as action and using the #selector(dismissKeyboard) form, but when I

UILabel with Tap Gesture Recognizer not working

淺唱寂寞╮ 提交于 2019-12-02 04:49:56
I have designed a UICollectionViewCell using XIB and in that custom cell I have an UILabel whose user interaction I have enabled. In my viewcontroller when I am designing the cell , Here is my code. UITapGestureRecognizer *buyNowTapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buyNowClicked:)]; buyNowTapped.numberOfTapsRequired = 1.0; cell.buy.tag = indexPath.row; cell.buy.userInteractionEnabled = YES; [cell.buy addGestureRecognizer:buyNowTapped]; -(void)buyNowClicked : (id)sender { UIButton *button; UILabel *label; if([sender isKindOfClass:[UIButton class]]) {

UITapGestureRecognizer working on UIImageView but not on UILabel

风格不统一 提交于 2019-12-02 02:59:28
I have a UITableViewCell class named CommentsTableViewCell which among other things includes a UIImageView and a UILabel . Code I'm using: let tapGesture = UITapGestureRecognizer(target: self, action: #selector(CommentsTableViewCell.showUserViewController)) nameLabel.userInteractionEnabled = true avatarRoundImageView.userInteractionEnabled = true nameLabel.addGestureRecognizer(tapGesture) avatarRoundImageView.addGestureRecognizer(tapGesture) As you can understand I have a function which shows another UIViewController whenever the UIImageView or the UILabel is tapped. What buffles me is that

UITapGestureRecognizer on a text field not as expected

江枫思渺然 提交于 2019-12-02 02:30:41
In my class I have 11 UITapGestureRecognizers in an array textViewRecognizer attached to 11 out of 100 UITextFields in an array boxArray. When a Textfield is tapped containing a UIGestureRecognizer it runs tappedTextView where I try to get the index of the first responder. However, due to some weird ordering in how things are executed, the action function only gives me the first responder of the previous first responder to the one that was just tapped. Also, I have to double tap to even select the text field I was going for! I need to use the tap function and not the text delegates so this has

How to detect which image has been tapped in swift

岁酱吖の 提交于 2019-12-01 07:24:42
问题 I have created 6 UIImageViews on a ViewController, and I am later going to add TapGestureRecognizers to all of them. I want to make it so that depending on what image has been clicked, another ViewController will open and display certain information. For this to happen, I need to know which image has been clicked. How would I do this in Swift? 回答1: UIGestureRecognizer has property 'view' this property is the view you add it to. For this example the imageView. func tap(gesture:

iOS swift UIImageView change image in tableView cell

本小妞迷上赌 提交于 2019-12-01 01:49:11
I have a strange problem in tableView Custom cell . for like Image action I write these code in Custom cell called FeedViewCell : self.like.isUserInteractionEnabled = true let CommenttapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(likehandleTap)) self.like.addGestureRecognizer(CommenttapGestureRecognizer) func likehandleTap(_ sender: UITapGestureRecognizer) { if self.like.image == UIImage(named: "like-btn-inactive") { self.like.image = UIImage(named: "like-btn-active") } else { self.like.image = UIImage(named: "like-btn-inactive") } } and TableViewController: func

iOS - Multiple Tap gesture recognizers

左心房为你撑大大i 提交于 2019-11-30 20:34:32
In my application, i've to detect single, double and triple taps. So, I'm using UITapGestureRecognizer. I'm using the following code: UITapGestureRecognizer *oneTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapGestureOnAnimal:)]; oneTap.numberOfTapsRequired = 1; UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTapGestureOnAnimal:)]; doubleTap.numberOfTapsRequired = 2; [doubleTap requireGestureRecognizerToFail:oneTap]; UITapGestureRecognizer* tripleTap = [[UITapGestureRecognizer alloc]

sending a parameter argument to function through UITapGestureRecognizer selector

不羁的心 提交于 2019-11-30 15:38:54
问题 I am making an app with a variable amount of views all with a TapGestureRecognizer. When the view is pressed, i currently am doing this func addView(headline: String) { // ... let theHeadline = headline let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleTap:")) // .... } but in my function "handleTap", i want to give it an additional parameter (rather than just the sender) like so func handleTap(sender: UITapGestureRecognizer? = nil, headline: String) { } How do

sending a parameter argument to function through UITapGestureRecognizer selector

三世轮回 提交于 2019-11-30 14:19:15
I am making an app with a variable amount of views all with a TapGestureRecognizer. When the view is pressed, i currently am doing this func addView(headline: String) { // ... let theHeadline = headline let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleTap:")) // .... } but in my function "handleTap", i want to give it an additional parameter (rather than just the sender) like so func handleTap(sender: UITapGestureRecognizer? = nil, headline: String) { } How do i send the specific headline (which is unique to every view) as an argument to the handleTap-function?

hitTest:WithEvent and Subviews

孤者浪人 提交于 2019-11-30 11:47:46
I have 2 views , but i want to make 1 view (virtually) bigger. if I place my tapGesture on v1, the tap gesture works with a bigger hit area but if I place my tapGesture on v2 it doesn't work ( actually it doesn't recognizes the tapGesture at all, even not inside the original bounds ) even though i loop through my TestView1 hittest method and the points get contained in the frame. #import "ViewController.h" @interface TestView1 : UIView @end @implementation TestView1 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { CGFloat radius = 100.0; CGRect frame = CGRectMake(0, 0, self