zacwest / ZSWTappableLabel

UILabel subclass for links which are tappable, long-pressable, 3D Touchable, and VoiceOverable.
MIT License
169 stars 37 forks source link

ZSWTappableLabelTapDelegate not called when UITapGestureRecognizer method is already in code #34

Closed ms-tii closed 5 years ago

ms-tii commented 5 years ago

I have UITapGestureRecognizer method already in my class and after implementing this pod on tap of PrivacyPolicy link, UITapGestureRecognizer method is called instead of ZSWTappableLabelTapDelegate.

Called this method on lable link tap @objc func handleTap(_ gestureRecognizer: UITapGestureRecognizer) { if contentView.frame.origin.y != 0{ if UIDevice.current.userInterfaceIdiom == .pad { moveTextField(moveDistance: 70, up: false) }else{ moveTextField(moveDistance: 0, up: false) } } self.contentView.resignFirstResponder() self.contentView.endEditing(true) }

This delegate is not called

func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedString.Key : Any] = [:]) { self.performSegue(withIdentifier: kToWebView, sender: nil) }

zacwest commented 5 years ago

The best way to handle this would be to add a delegate to your UITapGestureRecognizer and make gestureRecognizer(_:shouldReceive:) return false if tappableLabel.tappableRegionInfo(at:) returns non-nil.

dmitrysimkin commented 4 years ago

Worked for me, thanks

        let gr = UITapGestureRecognizer(target: self, action: #selector(onTapView))
        gr.delegate = self
        gr.cancelsTouchesInView = false
        addGestureRecognizer(gr)

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        let info = descriptionLabel.tappableRegionInfo(at: touch.location(in: descriptionLabel))
        return info == nil
    }