MLInputDodger 1.5.2

MLInputDodger 1.5.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最后发布2018年12月

molon 维护。



  • 作者
  • molon

MLInputDodger

License MIT  CocoaPods  CocoaPods  Build Status  Apps Using  Downloads 

我的库不寻求任何回报,但如果您使用此库,如果您喜欢,可以给它加星。 :)

MLInputDodger

原理

  • dodgeView表示哪个视图需要改变框架或改变contentOffset(contentInset)。
  • dodgeView中所有可以becomeFirstResponder的子视图将触发避让行为。
  • 子视图的inputView可能不只是键盘。没关系,这就是为什么库命名为MLInputDodger而不是MLKeyboardDodger。 :)

用法

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    self.view.shiftHeightAsDodgeViewForMLInputDodger = 50.0f;
    [self.view registerAsDodgeViewForMLInputDodgerWithOriginalY:self.view.frame.origin.y];
}

然后,可以成为FirstResponder的子视图将触发避让。
如果您需要为特殊响应者设置自定义的shiftHeight,请设置shiftHeightAsFirstResponderForMLInputDodger属性。

禁用默认的收起输入辅助视图

self.view.dontUseDefaultRetractViewAsDodgeViewForMLInputDodger = NO; //for all subviews of self.view

self.testView1.dontUseDefaultRetractViewAsFirstResponderForMLInputDodger = NO; //for sepecial

动画伴随

[[MLInputDodger dodger]setAnimateAlongsideBlock:^(BOOL show,UIView *dodgerView,UIView *firstResponderView,CGRect inputViewFrame) {
        if ([dodgerView isKindOfClass:[UIScrollView class]]) {
            ((UIScrollView*)dodgerView).scrollIndicatorInsets = ((UIScrollView*)dodgerView).contentInset;
        }
    }];
__weak __typeof(self)weakSelf = self;
    [self.tableView setAnimateAlongsideAsDodgeViewForMLInputDodgerBlock:^(BOOL show,UIView *dodgerView,UIView *firstResponderView,CGRect inputViewFrame) {
        __strong __typeof(weakSelf)sSelf = weakSelf;
        CGRect frame = sSelf.testAnimateAlongsideLabel.frame;
        if (show) {
            frame.origin.y = inputViewFrame.origin.y+kMLInputDodgerRetractViewDefaultHeight-kLabelBottomMargin-kLabelHeight;
        }else{
            frame.origin.y = sSelf.view.frame.size.height-kLabelBottomMargin-kLabelHeight;
        }
        sSelf.testAnimateAlongsideLabel.frame = frame;
    }];

提示

您可以将此类添加到UITableViewController禁用自动键盘,否则将影响库的实现。但_adjustForAutomaticKeyboardInfo:animated:lastAdjustment:是一个私有API,所以...

@implementation UITableView(DisableAutomaticKeyboard)
- (void)_adjustForAutomaticKeyboardInfo:(id)arg1 animated:(BOOL)arg2 lastAdjustment:(float*)arg3 {
    return;
}
@end