Adjust UIPopoverController position after resize

后端 未结 2 1467
渐次进展
渐次进展 2021-02-10 11:05

I have a UIPopoverController containing a UITableView. The popover is resized in its view controller\'s -viewDidAppear function to fit th

相关标签:
2条回答
  • 2021-02-10 11:38

    I think this may be the wrong way to go about it, since you're having to re-do the built-in behaviour that positions the arrow to begin with.

    I don't resize popover content in viewDidAppear. I set the contentSizeForViewInPopover property in the view controller's viewDidLoad method, e.g.:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.contentSizeForViewInPopover = CGSizeMake(320, 155); // sized for a 3-row UITableView
    }
    

    (Quick warning: if you're developing a universal app, this code will cause a run-time crash on devices running 3.1.x and below.)

    You can also set the content size for the popover controller before you present it, which should take care of your problem. Check out the popoverContentSize property.

    0 讨论(0)
  • 2021-02-10 11:47

    According to this answer, you can call presentPopoverFromRect:inView: on the popover again and it will reposition the arrow. I haven't tested this myself.

    0 讨论(0)
提交回复
热议问题