Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

keyboard resigning reduces popover height

I have a strange issue on ios 4.3.I have one of my screen in landscape mode, a button click presents a popover.My popover has a search bar.Whenever keyboard appears it automatically pushes my popover bit up.When I resign the keyboard , popover reduces in height.This is the issue only on ios 4.3.While in rest of the ios , my popover doesnot reduces in height after keyboard dismissal.

like image 876
Swastik Avatar asked Apr 01 '11 12:04

Swastik


2 Answers

None of the answers above worked for me. Apparently the keyboard scales the view and restores this scaling after the UIKeyboardDidHideNotification notification, making the presentPopoverFromRect method useless when applied handling this notification. The way I solved it was by delaying the latter call as follows:

- (void)viewDidLoad
{
    [super viewDidLoad];
    popup = nil;        //my ViewController with UITextField
    popover = nil;      //my UIPopoverController
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc addObserver:self
           selector:@selector(resizePopup:)
               name:UIKeyboardDidHideNotification
             object:nil];
}

- (void)doDelayedResize
{
    [popover presentPopoverFromRect:myButton.bounds inView:myButton permittedArrowDirections:UIPopoverArrowDirectionAny  animated:YES];
}

- (void)resizePopup:(NSNotification*)note
{
    [self performSelector:@selector(doDelayedResize) withObject:nil afterDelay:0.01]; 
}
like image 143
Koen Avatar answered Nov 15 '22 18:11

Koen


I answered a very similar question here: UIPopoverController's view controller gets resized after keyboard disappears

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];
}
like image 28
InsertWittyName Avatar answered Nov 15 '22 16:11

InsertWittyName



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!