setPopoverContentSize not working

2019-05-28 22:55发布

I have a UIPopoverController in a view, and the following method to update its CGSize:

-(void)updatePop:(CGSize)newSize
{
    NSLog(@"New Size: %@", NSStringFromCGSize(newSize));    
    [popoverSearch setPopoverContentSize:newSize animated:YES];
    NSLog(@"popoverContentSize: %@", NSStringFromCGSize(popoverSearch.popoverContentSize));
}

When the method runs, the console shows the following:

New Size: {320, 640}
popoverContentSize: {320, 409}

Does anyone have idea why it's happening? It happens specially in landscape...

1条回答
叛逆
2楼-- · 2019-05-28 23:24

I was having a similar problem in that I was unable to change the size of a popover controller during device rotation. I found the information that lead to my solution in a answer to a similar question.

Because I was presenting the popover from a Bar button, UIKit was "trying" to help by adjusting the size of the popover during rotation (because the position of the button might be different after a change to a different device orientation). Even though I knew exactly what size I wanted the popover to be in every case, it wasn't respecting my calls to setPopoverContentSize. My solution was to dismiss the popover in willAnimateRotationToInterfaceOrientation, then re-present the same popover in didRotateFromInterfaceOrientation after setting appropriate values for both contentSizeForViewInPopover and popoverContentSize. IHTH

查看更多
登录 后发表回答