MAGComfortTextInput 0.3.5

MAGComfortTextInput 0.3.5

测试测试过
语言语言 Obj-CObjective C
协议 MIT
发布最新版本2017年2月

Denis MatveevAlexander Gorbunov 维护。



  • 作者:
  • Denis Matveev

通过处理键盘显示行为,使使用 UITextField 和 UITextView 更容易。

支持的父视图

  • UIView
  • UIScrollView (及其子类,例如UITableView)

功能

  • 1. 将活动的 UITextField / UITextView (称为“输入字段”)居中于屏幕顶部和键盘顶部之间的空闲空间。
  • 2. 点击空白区域来关闭
  • 3. 按下 Next / Done 按钮执行操作
  • 4. 容易进行自定义

警告:

在 iOS 模拟器上进行测试时,必须启用键盘显示。为此,请打开 iOS 模拟器 -> 硬件 -> 键盘 -> 连接硬件键盘/切换软件键盘。 (此处为 CMD + K / CMD + SHIFT + K 组合键)

示例:

要运行示例工程,请克隆仓库,然后首先从 Example 目录中运行 pod install

要求:

MAGComfortTextInput 适用于 iOS 7+ (可能也适用于 6+,我不确定)。

安装:

MAGPdfGenerator 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 并运行 pod install

pod 'MAGComfortTextInput'

用法:

在 AppDelegate.m 中的 [self.window makeKeyAndVisible] 之前应准备 MAGKeyboardInfo。如果您手动创建窗口,那么在创建窗口后执行此操作。例如

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[[MAGKeyboardInfo sharedInstance] prepareKeyboardWithMainWindow:self.window];
[self.window makeKeyAndVisible];
...
}

否则,如果您使用启动界面,则应在窗口创建后首先调用此方法!

例如,您在您的 UIViewController 的 UIView 中有 3 个 UITextField 和 3 个 UITextView

@property (weak, nonatomic) IBOutlet UITextField *tf1;
@property (weak, nonatomic) IBOutlet UITextField *tf2;
@property (weak, nonatomic) IBOutlet UITextField *tf3;
@property (weak, nonatomic) IBOutlet UITextView *tv1;
@property (weak, nonatomic) IBOutlet UITextView *tv2;
@property (weak, nonatomic) IBOutlet UITextView *tv3;

@property (strong, nonatomic) MAGViewComfortTextInput *comfortTextInput;

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    [self configureTextFieldsForConvinientUsing];
    [self.tf1 becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.comfortTextInput resetWithResignFirstResponder];
}

- (MAGViewComfortTextInput *)configureTextFieldsForConvinientUsing {
    if (_comfortTextInput) {
        return _comfortTextInput;
    }

    _comfortTextInput = [[MAGViewComfortTextInput alloc] initWithOrderedTextInputControls:@[self.tf1,self.tv1,self.tf2,self.tv2,self.tf3,self.tv3 ] withOwnerView:self.view];
    _comfortTextInput.textInputControlDidEndEditingBlock = ^(UIView *textInputControl) {
        NSLog(@"DO SOMETHING");
    };
    _comfortTextInput.lastTextInputControlDidEndEditingBlock = ^(UIView *textInputControl) {
        NSLog(@"DO SOMETHING ON FINISH");
    };
    return _comfortTextInput;
}

例如,如果您的 UIViewController 中的 UIScrollView (或 UITableView) 中有 3 个 UITextField 和 3 个 UITextView,那么将初始化代码更改为以下内容

- (MAGViewComfortTextInput *)configureTextFieldsForConvinientUsing {
    if (_comfortTextInput) {
        return _comfortTextInput;
    }

    _comfortTextInput = [[MAGScrollViewComfortTextInput alloc] initWithOrderedTextInputControls:@[self.tf1,self.tv1,self.tf2,self.tv2,self.tf3,self.tv3 ] withOwnerView:self.view withScrollViewInsideOwnerViewWhereTextFieldsLocated:self.scrollView];
    _comfortTextInput.textInputControlDidEndEditingBlock = ^(UIView *textInputControl) {
        NSLog(@"DO SOMETHING");
    };
    _comfortTextInput.lastTextInputControlDidEndEditingBlock = ^(UIView *textInputControl) {
        NSLog(@"DO SOMETHING ON FINISH");
    };
    return _comfortTextInput;
}

已知问题:

不要使用位于 UITableView.tableHeaderView 和 UITableView.tableFooterView 中的 textInputControls,因为这些视图的隐藏逻辑(自动布局逻辑)导致其焦点工作不正确...

作者:

Denis Matveev,[email protected]

许可证

有关更多信息,请参阅LICENSE文件。