是否可以在 iOS 9 上使用 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