m1entus / MZFormSheetPresentationController

MZFormSheetPresentationController provides an alternative to the native iOS UIModalPresentationFormSheet, adding support for iPhone and additional opportunities to setup UIPresentationController size and feel form sheet.
MIT License
973 stars 146 forks source link

frameConfigurationHandler problem with keyboard #61

Closed Skornos closed 8 years ago

Skornos commented 8 years ago

Hi,

I am using frameConfigurationHandler to align my presented view to the bottom of the screen like this:

        formSheetController.presentationController.frameConfigurationHandler = ^(UIView *presentedView, CGRect currentFrame) {
            return CGRectMake(currentFrame.origin.x, weakSelf.view.frame.size.height - currentFrame.size.height, currentFrame.size.width, currentFrame.size.height);
        };

At the same time this view aligned to the bottom contains 2 input TextFields so I am also setting movementActionWhenKeyboardAppears

formSheet.presentationController.movementActionWhenKeyboardAppears = MZFormSheetActionWhenKeyboardAppearsMoveToTopInset;

The problem is that when I tap the textField the keyboard covers the whole bottom view which doesn't slide up. I suppose it is a conflict between setting my custom frame and displaying keyboard. Or am I doing something wrong?

Thanks :)

m1entus commented 8 years ago

As you can see here: https://github.com/m1entus/MZFormSheetPresentationController/blob/master/MZFormSheetPresentationController/MZFormSheetPresentationController.m#L486 If you set frameConfigurationHandler then you are responsible for keyboard movement as well.

Skornos commented 8 years ago

Thanks for your quick response. Would it be possible to adjust the library to pass the property keyboardVisible to the frameConfigurationHandler along with the self.presentedView and formSheetRect?

I think it makes sense because these properties are the ones which define how the frame should display and the frameConfigurationHandler is called when the keyboard appears. Otherwise I would need to register for keyboard notifications which seems redundant if you are doing this in your code already.

m1entus commented 8 years ago

Sure, that make sense, i also exposed isKeyboardVisible property in presentationController. Thanks.

MarkPolivchuk commented 8 years ago

I want to anchor the bottom of the form sheet to the top of the keyboard but don't know how to get the keyboard's frame (height specifically) without registering for notifications. Would it be possible to expose screenFrameWhenKeyboardVisible too?


EDIT:

Sorry, looked into the code further and realized you're already including the offset in the formSheetRect parameter.

    formSheetController.presentationController?.movementActionWhenKeyboardAppears = .AlwaysAboveKeyboard
    formSheetController.presentationController?.frameConfigurationHandler = { (view, formSheetRect, isKeyboardVisible) in

        ...

        // add 20 to anchor frame to bottom because it's the default internal margin
        if isKeyboardVisible {
            return CGRectMake(0, formSheetRect.origin.y+20, width, height)
        }
        else {
            return CGRectMake(0, 0, width, height)
        }
   }

anchors the form sheet to the keyboard when the keyboard appears.

New problem though, this is only true if the keyboard appears in the initial orientation that the form sheet was presented in. Presenting the sheet, rotating, and then opening the keyboard offsets the frame by an incorrect value, and rotating after presenting the keyboard breaks all of my form sheets subviews. Any ideas on how to fix this?

m1entus commented 8 years ago

use MZFormSheetActionWhenKeyboardAppearsAboveKeyboard for movementActionWhenKeyboardAppears property on presentationController

MarkPolivchuk commented 8 years ago

I'm using .AlwaysAboveKeyboard because my Form Sheet is full screen.

Here are a few screenshots of what I mean:

Present VC in landscape, open keyboard in landscape: (perfect!) image

Present VC in landscape, open keyboard in portrait: (VC isn't moving up enough) image

Present VC in portrait, open keyboard in landscape (VC is moving up too much) image

nizzam commented 5 years ago

What is the fixed for this ?