2

有谁知道,如何禁用 iPhone 3.0 上的剪切、复制和粘贴选项?

感谢您的帮助和时间。

4

3 回答 3

3

我也找不到太多关于为此目的使用canPerformAction:withSender:的文档。所以,我决定在退出应用程序时清除粘贴板。在我的 AppDelegate.m 中:

- (void)applicationWillTerminate:(UIApplication *)application {

  NSLog(@"application terminating");

  // Clear pasteboard to prevent pasting into other applications:
  UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
  pasteBoard.items = nil;

}

这适用于我的用户注释参考应用程序。我不介意用户在我的应用程序中复制和粘贴,但我希望他们不要重新发布我的原始内容。

在某些时候,我想要更细粒度的控制,也许使用canPerformAction:withSender:,这样我就可以允许用户复制/粘贴他们自己创建的内容。

于 2009-08-08T23:06:11.653 回答
3

在控制器类中重写此方法。

//隐藏剪切/复制/粘贴菜单

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender {

    if ( [UIMenuController sharedMenuController] )
    {
        [UIMenuController sharedMenuController].menuVisible = NO;

    }
    return NO;  
}
于 2010-02-18T19:24:04.580 回答
2

任何响应者(UIView 或 UIWindow 子类)都可以覆盖canPerformAction:withSender:方法,因此您可以为所有您不想允许的操作返回 NO。

请参阅UIResponder 文档...

于 2009-06-27T14:10:30.143 回答