开发者

Show UIDatePicker inside UIPopoverController after UIKeyboard is dismissed

开发者 https://www.devze.com 2023-03-10 14:09 出处:网络
I am pulling my hair out with this one. I have a table inside a popover which allows the user to edit some data.Most of these editable cells need the user to enter data via the keyboard, but one need

I am pulling my hair out with this one.

I have a table inside a popover which allows the user to edit some data. Most of these editable cells need the user to enter data via the keyboard, but one needs a UIDatePicker. Whe开发者_C百科n the UIDatePicker is presented to the user, it slides in from the bottom of the popover by grabbing the size of the view and performing an animation. However, if this happens after the keyboard is dismissed then the size of the view is grabbed before the popover is reset back its original position (i.e. when the popover is resizing back to normal size after being 'squashed" toward the top the the screen). This leaves the UIDatePicker halfway up the popover.

I have tried adding a delay, and using an UIKeyboardWillHideNotification, but I cannot get this to work.

How can I wait for the popover to finish resizing before I grab the size of the view and perform the animation?

Update 1

I managed to work this out myself, but I'll post the answer here just incase anyone else needs it. Basically I set up a CGRect variable which gets populated with the views bounds when the view loads. Then instead of grabbing the bounds of the view each time I want to animate the UIDatePicker in, I simply use the CGRect variable instead.

Update 2

The above fix works in most cases, but not for all. The problem I am now having is when a new popover is displayed before the keyboard is fully dismissed (i.e. half way down it's animation out). This gives bounds at it's current size, before it is then resized to the actual size it needs to be. Also, the popover doesn't seem to resize back to its original size once the keyboard is dismissed.

Any ideas folks?


Solved.

When keyboard is dismissed in the popover delegate, I check that the popover is being displayed and then reposition it to its original size and location. I have the code if anyone is interested. Just comment me up.

0

精彩评论

暂无评论...
验证码 换一张
取 消