UIPopoverController's view controller gets resized after keyboard disappears

后端 未结 1 1623
情深已故
情深已故 2020-12-15 14:57

I have a view controller inside a UIPopoverController. When I open a keyboard for a text field that belongs to the view in the popover, the view resizes to acco

相关标签:
1条回答
  • 2020-12-15 15:24

    Had this problem myself recently.

    The way I got around it was to observe the keyboard disappearing in the controller which controls the UIPopoverController:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentSearchPopover) name:UIKeyboardDidHideNotification object:nil];
    

    And then in -presentSearchPopover, present the UIPopoverController again (it's quite a seamless transition):

    - (void)presentSearchPopover
    {
        self.searchPopoverController.popoverContentSize = CGSizeMake(width, height);
    
        [self.searchPopoverController presentPopoverFromRect:someRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    }
    

    Don't forget to remove the observer in -dealloc or similar too:

    - (void)dealloc
    {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
    
        [super dealloc];
    }
    
    0 讨论(0)
提交回复
热议问题