自定义输入视图控制器

Custom input view controller

是否可以在 iOS9 上使用 UIInputViewController 子类作为输入视图?我已经尝试设置 inputViewController 属性 但是当我的文本字段成为第一响应者时没有自定义视图控制器出现。

@interface InputViewController : UIInputViewController

@end

@implementation InputViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    datePicker.translatesAutoresizingMaskIntoConstraints = NO;

    [self.inputView addSubview:datePicker];

    [datePicker.leadingAnchor constraintEqualToAnchor:self.inputView.leadingAnchor].active = YES;
    [datePicker.trailingAnchor constraintEqualToAnchor:self.inputView.trailingAnchor].active = YES;
    [datePicker.topAnchor constraintEqualToAnchor:self.inputView.topAnchor].active = YES;
    [datePicker.bottomAnchor constraintEqualToAnchor:self.inputView.bottomAnchor].active = YES;
}

@end

@interface TextField: UITextField

@property (nonatomic, readwrite, strong) UIInputViewController *inputViewController;

@end

@implementation TextField
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.textField.inputViewController = [[InputViewController alloc] init];
}

@end

原来丢失的部分是:

self.view.translatesAutoresizingMaskIntoConstraints = NO;

非常沮丧 UIInputViewController 不会自动执行此操作。