Present UIPopoverController in same position with changing just arrow offset

后端 未结 3 1847
不知归路
不知归路 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:31

    For my popover I wanted the arrow to be top-left instead of top-center (which is default).

    I've managed to get the result below (screenshot) by setting the popoverLayoutMargins property of the UIPopoverController. You can use it to reduce the screen-area used in the internal calculations of the UIPopoverController to determine where to show the popover.

    UIPopovercontroller arrow on the left

    The code:

    // Get the location and size of the control (button that says "Drinks")
    CGRect rect = control.frame;
    
    // Set the width to 1, this will put the anchorpoint on the left side
    // of the control
    rect.size.width = 1;
    
    // Reduce the available screen for the popover by creating a left margin
    // The popover controller will assume that left side of the screen starts
    // at rect.origin.x
    popoverC.popoverLayoutMargins = UIEdgeInsetsMake(0, rect.origin.x, 0, 0);
    
    // Simply present the popover (force arrow direction up)
    [popoverC presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    

    I think you'll be able to get the desired result by tweaking the above.

提交回复
热议问题