How do you REALLY remove Copy from UIMenuController

后端 未结 6 1260
悲&欢浪女
悲&欢浪女 2020-12-04 22:31

There apparently used to be an easy way to prevent the \"More...\" label from appearing in UIMenuController when you added more than one custom menu item. You just had to re

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 23:28

    Here is a solution for iOS5.x that works for me. It's by Josh Garnham, suggesting creating a UIWebBrowserView Category to catch the copy:, paste:, define: selectors.

    http://ios-blog.co.uk/iphone-development-tutorials/rich-text-editing-highlighting-and-uimenucontroller-part-3/

    @implementation UIWebBrowserView (UIWebBrowserView_Additions)
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        return NO;
    }
    @end
    

    Note just FTR: There's a slight typo on that excellent web page. Here's precisely how you do it. Apple will 100% reject this. Make a category

    enter image description here

    (You have to type in "UIWebBrowserView" since Xcode won't bring up private classes.) Full text of the .h and .m files:

    // .h file...
    #import "UIWebBrowserView+Tricky.h"
    @interface UIWebBrowserView : UIView
    @end
    @interface UIWebBrowserView(Tricky)
    @end
    
    // .m file...
    #import "UIWebBrowserView+Tricky.h"
    @implementation UIWebBrowserView (Tricky)
    -(BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
    NSLog(@"don't let Apple see this");
    return NO;
    }
    @end
    

    For the record, a "single click" will still bring up the annoying spellchecker suggestions! But otherwise it does remove the double-click-context-menu totally, it is 100% rejected by Apple.

提交回复
热议问题