UITapGestureRecognizer – make it work on touch down, not touch up?

Use a UILongPressGestureRecognizer and set its minimumPressDuration to 0. It will act like a touch down during the UIGestureRecognizerStateBegan state. For Swift 4+ func setupTap() { let touchDown = UILongPressGestureRecognizer(target:self, action: #selector(didTouchDown)) touchDown.minimumPressDuration = 0 view.addGestureRecognizer(touchDown) } @objc func didTouchDown(gesture: UILongPressGestureRecognizer) { if gesture.state == .began { doSomething() } } For Objective-C -(void)setupLongPress { self.longPress … Read more

Click Event on UIImageView programmatically in ios

SWIFT 5 let preArrowImage : UIImageView // also give it frame let singleTap = UITapGestureRecognizer(target: self, action: #selector(tapDetected)) preArrowImage.isUserInteractionEnabled = true preArrowImage.addGestureRecognizer(singleTap) //Action func tapDetected() { print(“Imageview Clicked”) } Objective-c UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)]; singleTap.numberOfTapsRequired = 1; [preArrowImage setUserInteractionEnabled:YES]; [preArrowImage addGestureRecognizer:singleTap]; -(void)tapDetected{ NSLog(@”single Tap on imageview”); }

UITapGestureRecognizer tap on self.view but ignore subviews

You should adopt the UIGestureRecognizerDelegate protocol inside the self object and call the below method for checking the view. Inside this method, check your view against touch.view and return the appropriate bool (Yes/No). Something like this: – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:yourSubView]) { return NO; } return YES; } Edit: Please, also … Read more

UITapGestureRecognizer – single tap and double tap

UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)] autorelease]; singleTap.numberOfTapsRequired = 1; [self.view addGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)] autorelease]; doubleTap.numberOfTapsRequired = 2; [self.view addGestureRecognizer:doubleTap]; [singleTap requireGestureRecognizerToFail:doubleTap]; Note: If you are using numberOfTouchesRequired it has to be .numberOfTouchesRequired = 1; For Swift let singleTapGesture = UITapGestureRecognizer(target: self, action: #selector(didPressPartButton)) singleTapGesture.numberOfTapsRequired = 1 view.addGestureRecognizer(singleTapGesture) let … Read more

UIButton inside a view that has a UITapGestureRecognizer

You can set your controller or view (whichever creates the gesture recognizer) as the delegate of the UITapGestureRecognizer. Then in the delegate you can implement -gestureRecognizer:shouldReceiveTouch:. In your implementation you can test if the touch belongs to your new subview, and if it does, instruct the gesture recognizer to ignore it. Something like the following: … Read more

UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath

Ok, finally found it after some searching through gesture recognizer docs. The solution was to implement UIGestureRecognizerDelegate and add the following: #pragma mark UIGestureRecognizerDelegate methods – (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:autocompleteTableView]) { // Don’t let selections of auto-complete entries fire the // gesture recognizer return NO; } return YES; } That took … Read more

Create tap-able “links” in the NSAttributedString of a UILabel?

In general, if we want to have a clickable link in text displayed by UILabel, we would need to resolve two independent tasks: Changing the appearance of a portion of the text to look like a link Detecting and handling touches on the link (opening an URL is a particular case) The first one is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)