iOS 13.1 UITextView delegate method shouldInteract called when scrolling on attachment

前端 未结 2 625
情深已故
情深已故 2021-02-13 04:40

I\'m using the UITextView delegate method to do some custom work like opening a in-app browser when user tapping on URL or attachment:



        
2条回答
  •  暖寄归人
    2021-02-13 04:58

    I just encountered the same frustrating issue in iOS 13. Here is a fix that worked for me in Swift inspired by Mihai's answer above.

    func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    
        switch interaction {
        case .invokeDefaultAction:
            if textView.gestureRecognizers?.contains(where: {$0.isKind(of: UITapGestureRecognizer.self) && $0.state == .ended}) == true {
    
                // Handle your custom logic here.
    
                return false
            }
            return true
        case .presentActions:
    
            // Default action.
    
            return true
        case .preview:
    
            // Default action.
    
            return true
        @unknown default:
            fatalError()
        }
    }
    

提交回复
热议问题