禁用复制粘帖功能

2021-01-26 11:06:48 浏览数 (1)

在SDK3.0中添加了复制粘帖功能,但是有时候这个新功能可能对你的应用造成不必要的麻烦。 今天在网上查到了这个方法,可以在Responder链上禁用复制粘帖功能。

代码语言:javascript复制
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
    {
        if (action == @selector(xxx)
            return NO;
        return [super canPerformAction:action withSender:sender];
    }

其中xxx就是你要禁用的方法,比如copy,cut,paste等 这是官方文档对这个方法的说明

canPerformAction:withSender: Requests the receiving responder to enable or disable the specified command in the user interface. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender Parameters action A selector that identifies a method associated with a command. For the editing menu, this is one of the editing methods declared by the UIResponderStandardEditActions informal protocol (or example, copy:). sender The object calling this method. For the editing menu commands, this is the shared UIApplication object. Depending on the context, you can query the sender for information to help you determine whether a command should be enabled. Return Value YES if the the command identified by action should be enabled or NO if it should be disabled. Returning YES means that your class can handle the command in the current context. Discussion This default implementation of this method returns YES if the responder class implements the requested action and calls the next responder if it does not. Subclasses may override this method to enable menu commands based on the current state; for example, you would enable the Copy command if there is a selection or disable the Paste command if the pasteboard did not contain data with the correct pasteboard representation type. If no responder in the responder chain returns YES, the menu command is disabled. Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command. This method might be called more than once for the same action but with a different sender each time. You should be prepared for any kind of sender including nil. For information on the editing menu, see the description of the UIMenuController class. Availability Available in iPhone OS 3.0 and later. Declared In UIResponder.h


  • Previous iPhone应用程序名称本地化
  • Next loadView vs viewDidLoad

0 人点赞