iphone:Pop up button in UIWebView

让人想犯罪 __ 提交于 2019-12-05 08:36:29

The popup you refer to is called a UIMenuController. You can access the [UIMenuController sharedMenuController] method to get the menu controller. You can then add your own UIMenuItems to the menu controller.

UIMenuItem* myBtn1 = [[[UIMenuItem alloc] initWithTitle: @"Button 1" action:@selector( onButton1: )] autorelease];
UIMenuItem* myBtn2 = [[[UIMenuItem alloc] initWithTitle: @"Button 2" action:@selector( onButton2: )] autorelease];
UIMenuController* mc = [UIMenuController sharedMenuController];
mc.menuItems = [NSArray arrayWithObjects: myBtn1, myBtn2, nil];

Now implement the methods

- (void) onButton1: (UIMenuController*) sender
{
}

- (void) onButton2: (UIMenuController*) sender
{
}

For more detail refer apple's Doc.

Edit

you can implement Long Gesture

UILongPressGestureRecognizer* gr = [[[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector( onShowMenu: ) ] autorelease];
   [_myview addGestureRecognizer: gr];



- (void) onShowMenu: (UIGestureRecognizer*) sender
{
    [sender.view becomeFirstResponder];

    UIMenuController* mc = [UIMenuController sharedMenuController];

    CGRect bounds = sender.view.bounds;

    [mc setTargetRect: sender.view.frame inView: sender.view.superview];
    [mc setMenuVisible: YES animated: YES];
}

you can create a View Controller, and in the view controller's .xib file you can add your buttons.

then you can call that viewcontroller in the UIPopover..and load that view controller in it.

Now as you want to show this popover in the index page only, for this you have to keep a track of pages like pages form 1-3 are of index page so the popOver should be seen on that page. and when you click on the index link you can use the webView delegate function i.e

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType

under this function you can apply your logic and initiate the popover that will be seen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!