Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

ios - UIPopoverController's view controller gets resized after keyboard disappears

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 accommodate the keyboard. However, the view doesn't go back to the original size when the keyboard is dismissed.

Any ideas how to get it to resize back to what it was?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...