Move UIView up when the keyboard appears in iOS

后端 未结 18 1840
再見小時候
再見小時候 2020-11-28 20:38

I have a UIView, it is not inside UIScrollView. I would like to move up my View when the keyboard appears. Before I tried to use this solution: How can I make a UITextField

18条回答
  •  一个人的身影
    2020-11-28 20:45

    i just created a lightweight keyboard handler to follow keyboard frame.

    Usage:

     self.keyboardHandler = [EDKeyboardHandler new];
    
      [self.keyboardHandler listenWithBlock:^(KeyboardInfo *model)
      {
        //adjust view positions according to keyboard position here
      }];
    

    and the KeyboardInfo model has the following properties:

    typedef enum : NSUInteger {
        KeyboardStatusDidShow,
        KeyboardStatusWillShow,
        KeyboardStatusDidHide,
        KeyboardStatusWillHide,
    } KeyboardStatus;
    
    @interface KeyboardInfo:NSObject
    
    @property (nonatomic,readonly) NSTimeInterval animationDuration;
    @property (nonatomic,readonly) CGRect keyboardFrame;
    @property (nonatomic,readonly) NSInteger animationCurve;
    @property (nonatomic,readonly) KeyboardStatus status;
    
    @end
    

    check GitHub project for details and cocoaPods integration.

提交回复
热议问题