Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the coordinates of a popover on the fly

Background:

I need to display a popover from a imageview (rect not barbutton) which has a search field.The popover needs to be presented from a UIModalPresentationFormSheet.This is successfully achieved

Problem:

The problem I'm facing (in Landscape mode) is when the keyboard is shown the modal form sheet shifts up and with it my frame for the popover.Hence the popover remains in its original position (before the keyboard was shown) and the presented rect is shifted up. The solution i applied is to represent(using presentPopoverFromRect) the popover in -(void)didShowKeyBoard:(NSNotification*) notif from the changed rect and do the same in -(void)didhideKeyBoard:(NSNotification*) notif.This works fine but the transition is very fast and bouncy . So, how can i achieve a smooth transition for this?

What I have tried

I tried :

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:5.0f];
[_statePopover presentPopoverFromRect:stateHandler.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO];
[UIView commitAnimations];

but it didn't work.

Can someone please direct me to the correct way of doing this?
Any help is highly appreciated.

like image 952
Prathamesh Saraf Avatar asked Jun 03 '13 11:06

Prathamesh Saraf


1 Answers

Well this partially solved my issue . I used a dispatch to delay the popover presentation.It goes as given below:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_USEC), dispatch_get_current_queue(), ^{
    [_statePopover presentPopoverFromRect:statehandler.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
});

This works as required when my keyboard is dismissed but the same snippet fails to deliver desired result when the keyboard is shown.

Please leave comments if any one happens to know why it is behaving like this.Thank you!!

like image 139
Prathamesh Saraf Avatar answered Nov 18 '22 17:11

Prathamesh Saraf