LinkedInAttic / LayoutKit

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
http://layoutkit.org
Apache License 2.0
3.16k stars 267 forks source link

Best way to reposition view? #92

Closed stevejcox closed 7 years ago

stevejcox commented 7 years ago

I'm using LayoutKit to create a Form which is centered in the screen.

All works great, however I need to reposition the form layout, which is in a sublayout when a form field is selected due to the keyboard coming onto screen.

Other than keeping a reference to the view and remaking the layout, is there a 'right' way to reposition?

The issue I am having right now is that when I remake the views the textfield used within the form loses focus, so they keyboard immediately hides again.

func keyboardWillShow(notification: NSNotification) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
            print("Show")

            if let mainLayout = mainLayout {
                mainLayout.arrangement(height: view.frame.height - keyboardSize.height).makeViews(in: view)
            }
         }
    }

    func keyboardWillHide(notification: NSNotification) {
        print("Hide")

        if let mainLayout = mainLayout {
            mainLayout.arrangement(width: view.frame.width, height: view.frame.height).makeViews(in: view)
        }
    }
stevejcox commented 7 years ago

Just used prepareAnimation which has repositioned everything as desired.