6

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.

nevan king
  • 112,709
  • 45
  • 203
  • 241
Prathamesh Saraf
  • 709
  • 4
  • 14
  • did you try to change co-ordinates of the popover according to the orientation? – Radu Jun 03 '13 at 12:08
  • @Radu In portrait i do not face the above issue. In landscape, as i stated in my question, i re-present it from the rect which is already shifted its position . The popover then correctly assumes the new position of the shifted rect.The problem i am facing is in its transition.Its not smooth. – Prathamesh Saraf Jun 03 '13 at 12:21
  • I had this kind of problem in other places Try putting all the transition code in a UIView animation - i used this trick for some keyboard an Table animation maybe it will work for you – Radu Jun 03 '13 at 12:23
  • Thanks for the advice Radu but I tried that to no avail.I tried the block animation approach too.I even made a series of y-coord value changes for transition but it did not provide satisfactory result. i am using the animation to delay a lot of things in my code but this is one thing where its failing and i have no clue why. – Prathamesh Saraf Jun 03 '13 at 12:29
  • 1
    maybe this will help http://stackoverflow.com/questions/5874146/close-uipopover-on-rotation-with-a-fadeout-animation. you could try dismissing and then reshowing the popover – Radu Jun 03 '13 at 12:44
  • I had actually thought of that but didn't try .. may be its time i should. :) – Prathamesh Saraf Jun 03 '13 at 12:47
  • one more idea popped to mind if you use [UIView animateWithduration:0.5f animations:^{[_statePopover presentPopoverFromRect:stateHandler.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:NO]; }completion:nil]; wat result do you get ? – Radu Jun 03 '13 at 13:45
  • 1
    The same fast and bouncy transition.It's not smooth.Actually i have got it to go smooth when i dismiss the keyboard. using a delay through a dispatch like so: 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]; }); The same thing doesn't work when the keyboard is shown. – Prathamesh Saraf Jun 04 '13 at 05:29
  • That's great you should put this as an answer and mark your answer as solved. – Radu Jun 04 '13 at 07:40

1 Answers1

1

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!!

Prathamesh Saraf
  • 709
  • 4
  • 14