代码之家  ›  专栏  ›  技术社区  ›  nevan king

有创建光泽剪切/复制弹出窗口的界面吗

  •  0
  • nevan king  · 技术社区  · 15 年前

    有没有一种方法可以创建一个黑色的有光泽的弹出窗口,类似于复制和粘贴文本的弹出窗口。我只想提供一些信息,所以我想要的行为更接近键盘弹出窗口在您键入字母时的工作方式,但是我想要的外观是复制/粘贴对话框。

    这些对公众开放,还是我必须创建自己的实现?

    2 回复  |  直到 13 年前
        1
  •  1
  •   Jasarien    15 年前

    复制/剪切/粘贴用户界面可以免费使用uikit中的任何基于文本的用户界面控件(uitextfield、uitextview等),但如果您想将类似样式的用户界面用于应用程序的其他部分,则必须创建自己的用户界面。

        2
  •  0
  •   nzeltzer    13 年前

    您要查看uimenuitemcontroller。示例项目“CopyPasteTile”提供了一个自定义实现的示例。

    今天早上第二次出现这种情况!

    下面是一些示例代码,用于将自定义菜单项添加到uiview子类(它假定您已添加了具有适当目标操作的长按手势识别器):

    - (BOOL)canBecomeFirstResponder {
        return YES;
    }
    
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        if (action == @selector(laughOutLoud:))
            return YES;
        return NO;
    }
    
    - (void)laughOutLoud:(id)sender {
        NSLog(@"LOL!");
    }
    
    - (void)gestureRecognizerDidPress:(UILongPressGestureRecognizer*)recognizer {
        if ([recognizer state] == UIGestureRecognizerStateBegan) {
            // Important: the view must become the first responder,
            // and implement the canBecomeFirstResponder method.
            [self becomeFirstResponder];
            UIMenuController *controller = [UIMenuController sharedMenuController];
            UIMenuItem *testItem1 = [[UIMenuItem alloc] initWithTitle:@"Laugh" action:@selector(laughOutLoud:)];
            [controller setMenuItems:[NSArray arrayWithObject:testItem1]];
            [controller update];
            // In real life, the target rect should represent the selection
            [controller setTargetRect:CGRectZero inView:self];
            [controller setMenuVisible:YES animated:YES];
        }
    }