如何清除UIMenuController中的COPY UIMenuItem [英] How to remove th COPY UIMenuItem in UIMenuController

查看:172
本文介绍了如何清除UIMenuController中的COPY UIMenuItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序并使用UIWebViews。我计划自定义UIMenuItems,当我突出显示字符串在UiWebView(复制,选择所有,剪切等等)弹出。我尝试删除这些menuItem,但我无法删除COPY菜单项。



我需要你的帮助。



感谢,
ZaldzBugz

解决方案

你要做一些劫持。我甚至不知道是否可能。看起来它可能响应一个名为UILongPressGestureRecognizer的手势事件。



您需要找出手势添加到哪个视图。类似这样的东西。

  NSArray * gestures = myWebView.gestureRecognizers; 
for(int i = 0; i <[gestures count]; i ++){
UIGestureRecognizer g = [gestureings objectAtIndex:i];
if([g isKindOfClass:UILongPressGestureRecognizer.Class]){
[myWebView removeGestureRecognizer:g];
break;
}
}

但我不认为手势在UIWebview直接。

 <$> 




$ b

c $ c> UIScrollView * sview = [[mywebview subviews] objectAtIndex:0];

如果不在那个,那么它可能在视图上是最顶部,这是我怀疑。它是一个未记录的视图类型,但如果你把它作为一个UIView的方法,我们正在调用,它可能是安全的。此外,因为你将它视为一个UIView,它是不违反规则,只要我理解。

  UIScrollView * sview = [[mywebview subviews] objectAtIndex:0]; 
UIView * realWebView = [[sview subviews] objectAtIndex:10];

我没有编写代码段(未经测试)尝试删除手势所有的视图是因为重要的是你知道你从哪个视图中删除它。



删除它后,你需要编写自己的UILongPressGestureRecognizer,然后添加新的



您已经失去了所有的复制选择等功能,但现在你可以实现自己的。



如果你想要一些旧的功能,我想我知道你如何能得到它,但我不能答应这是允许或安全。



在移除手势之前,您需要将方法覆盖到UIView。您应该能够在当前工作类文件中(在文件顶部)



  @implementation UIView )
- (BOOL)responsesToSelector:(SEL)aSelector {
printf(SELECTOR:%s\\\

[NSStringFromSelector(aSelector)UTF8String]

return [super responsesToSelector:aSelector];
}
@end



我不能承诺任何东西,记录在您的视图中调用的EVERY方法的名称。



运行应用程序并执行复制,粘贴,选择,选择所有方法。您的日志应显示当您按按钮时调用的方法。当你按下一个按钮时,它可能会显示几种方法,你可能只是想要的第一个。



现在当你创建一个menuItem,你知道要分配给它的选择器。 p>

这只是一个猜测。希望它有帮助。


I am developing an iPhone application and worked with UIWebViews. I planned to customize the UIMenuItems thats popped up when i highlight strings in UiWebView (Copy, Select All, Cut, etc.). I tried removing those menuItems but i cannot remove the COPY menu item.

I need your help guys.

Thanks, ZaldzBugz

解决方案

You're going to have to do some hijacking. I don't even know if it is possible. It looks like it probably responds to a gesture event called UILongPressGestureRecognizer.

You need to find out what view has the gesture added to it. something like this.

NSArray *gestures = myWebView.gestureRecognizers;
for(int i=0;i<[gestures count];i++){
    UIGestureRecognizer g = [gestures objectAtIndex:i];
    if([g isKindOfClass:UILongPressGestureRecognizer.Class]){
       [myWebView removeGestureRecognizer:g];
       break;
    }
}

but I don't think the gesture is on the UIWebview directly. It is on one of its subviews.

So it might be on this subview

UIScrollView *sview = [[mywebview subviews] objectAtIndex:0];

If not on that one then it is probably on the view that is on top the most, which is what I suspect. It is an undocumented View type, but if you treat it as a UIView for the methods we are calling, it is presumably safe. Also, because you are treating it as a UIView, it isn't against the rules as far as I understand.

UIScrollView *sview = [[mywebview subviews] objectAtIndex:0];
UIView *realWebView = [[sview subviews] objectAtIndex:10];

The reason I didn't write the snippet (which is untested) to try to remove the gesture from all of the views is because it is important you know which view you remove it from.

After you remove it, you need to write your own UILongPressGestureRecognizer and then add the new one to the respective view (the view it was removed from).

You have lost all your functionality of copy select etc... but now you can implement your own.

If you want some of the old functionality, I think I know how you can get it back, but I can't promise this is allowed or safe.

Before you remove the gesture you need to override a method to UIView. You should be able to do it in your current working class file (at the top of the file)

@implementation UIView (extended)
     -(BOOL) respondsToSelector:(SEL)aSelector {
          printf("SELECTOR: %s\n", 
            [NSStringFromSelector(aSelector) UTF8String]);

          return [super respondsToSelector:aSelector];
     }
@end

I can't promise anything, but this should log the name of EVERY method that is called in your view.

Run your app and execute the copy,paste,select,select all methods. Your log should show what methods get called when you press the buttons. It may show several methods when you push a button, you probably just want the first.

Now when you create a menuItem you know what selector to assign to it.

This is all just a guess. Hope it helps.

这篇关于如何清除UIMenuController中的COPY UIMenuItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆