Present UIPopoverController in same position with changing just arrow offset

后端 未结 3 1840
不知归路
不知归路 2020-12-29 08:04

My goal is to keep same coordinates for a UIPopoverController with just changing arrow offset. So basically i have three buttons touching each of them shows up a popover. Wh

3条回答
  •  一向
    一向 (楼主)
    2020-12-29 08:14

    Yes, you can do that. You have to create an aux view, with alpha=0.0f, and use it to guide the arrow.

    For example:

    auxView = [[UIView alloc] initWithFrame:firstButton.frame];
    auxView.alpha = 0.0 ;
    auxView.userInteractionEnabled = NO;
    [firstButton.superView addSubview:auxView];
    [auxView release];
    

    Ok, now you open popover using that view as arrow's guide.

    [thePopoverController presentPopoverFromRect:auxView.bounds inView:auxView
                permitedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
    

    And now you only have to move the view:

    auxView.frame = secondButton.frame;
    

    Use animations for that move if you want.

    One more thing, for this kind of arrow to button, I prefer that the arrow touches the button. You can use:

    presentPopoverFromRect:CGRectInset(auxView.bounds, 4.0, 4.0)
    

提交回复
热议问题