This project is designed to solve problems where the floppy and input box locations do not match when the input box is nested in multiple layers. the GitHub source link for the project is:
https://github.com/crazycodeboy/KeyboardObserver/blob/master/KeyboardObserver/ KEYBOARDOBSERVER.M
first, the observer pattern implementation principleThe Observer pattern defines a one-to-many dependency that allows multiple observer objects to listen to a Subject object at the same time. When the subject object changes in state, all observer objects are notified so that they can update themselves. In this project, its implementation principle is mainly embodied in the following operations:
-(void)addGlobalKeyboardObserver
Add a keyboard viewer to all the input boxes in the interface,Add the listener to the event source,The ENTER key listens, touches the other area listens. Realizewhen the floppy disk pops up to automatically control the display position of the input box to prevent it from being obscured by the floppy disk, the floppy disk is hidden and the interface is restored when the key is outside the touch input box or when you press the ENTER key.
-(void)removeGlobalKeyboardObserver
Removes the keyboard viewer from all input boxes in the interface.
-(void)addKeyboardObserver
Adds a keyboard viewer to the specified input box,Add the listener to the event source,The ENTER key listens, touches the other area listens.realize when the floppy disk eject automatically control the display position of the input box to prevent being obscured by the floppy disk, when the touch input box outside the position or press the floppy key, the floppy disk hidden, interface recovery.
-(void)removeKeyboardObserver
Removes the keyboard observer for the specified input box.
-(void)addSimpleKeyboardObserver
Adds a keyboard viewer to the specified input box,Add the listener to the event source,Touch other areas to listen.implement automatic control of the display position of the input box when the floppy disk pops up to prevent it from being obscured by a floppy disk, hide the floppy disk when it is outside the touch input box or press the return key of the floppy disk, and restore the interface.。
-(void)removeKeyboardObserver
Removes the keyboard observer for the specified input box.
-(void)registerKeyboardNotifications
Event Source Change trigger event (specific subject role status change, notify Observer).
-(void)removeKeyboardNotifications
removes the listener from the event source and no longer triggers the event.
second, the role of the Observer model 1. Automatically control the display position of the input box when the floppy disk pops up to prevent the floppy disk from being obscured.
2. The floppy disk is hidden and the interface is restored when the key is outside the touch input box or when you press the return key of the floppy disk.
3. Support to add monitoring and removal of all input boxes to the entire page.
4. Support for adding monitoring and removing listeners for the specified input box.
5. Simple to use, a single line of code to complete the listening configuration.
Observer pattern parsing in keyboard projects