简体   繁体   中英

UITextView remove UILongPressGestureRecognizer

I have an UITextView which has set all the dataDetectionTypes. I want to remove the UILongPressGestureRecognizer because the action sheet that appears after long press, on a phone number text or a calendar event text, isn't showing correctly. It doesn't present the cancel button so I need to remove the UILongPressGestureRecognizer. Does anybody have an idea?

Do you know why my actionSheet doesn't present the cancel button? Please help! This issue is reproducible on iOS 5 and 6 and for devices with 3.5 inch display or less

I'm just going to expand on what has been said in the comments above. In order to do this effectively, you're going to want to create a subclass of the UITextView class. Doing so will allow you to implement UIResponder's canPerformAction: function, which will allow you to selectively decide which options you want available on the popup. You can modify the below code to allow for any combination of cut/copy/paste/select... that you want, or if you want to prevent the popup all together, simply return NO from this function without calling its super implementation.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(paste:) || action == @selector(select:) || action == @selector(selectAll:)) {
        return NO;
    }
    return [super canPerformAction:action withSender:sender];
}

Make sure this is done in a subclass though!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM