1

是否可以在 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
4

1 回答 1

3

原来缺少的部分是:

self.view.translatesAutoresizingMaskIntoConstraints = NO;

非常令人沮丧的是UIInputViewController不会自动执行此操作。

于 2015-11-26T14:03:53.397 回答