输入附件视图显示在UIAlertController之类的对象上

时间:2016-11-23 07:23:05

标签: ios swift inputaccessoryview

我正在使用输入附件以下列方式查看。

override var canBecomeFirstResponder: Bool {
    return true
}

override var inputAccessoryView: UIView? {
    return self.userInputView
}

此外,在viewDidAppear方法中,我正在使用:

let _ = self.becomeFirstResponder()

这是我必须的,因为我的viewController是一个childViewController。

无论如何,我不知道为什么,但是当我呈现UIAlertController并且键盘处于活动状态时,键盘会关闭,inputAccessoryView也会消失,然后突然显示在UIAlertController上方。

有人经历过这样的事吗?

谢谢

编辑 - 添加了图片: Shows over the UIAlertController

1 个答案:

答案 0 :(得分:0)

这将解决..!

请勿使用名称' inputAccessoryView

- (UIView *)CustominputAccessoryView { if (!keyboardinputAccessoryView) { CGRect accessFrame = CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, 40.0); keyboardinputAccessoryView = [[UIView alloc] initWithFrame:accessFrame]; keyboardinputAccessoryView.backgroundColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.6]; UIButton *compButton = [UIButton buttonWithType:UIButtonTypeCustom]; compButton.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-60, 0.0, 50, 40.0); [compButton setTitle: @"Done" forState:UIControlStateNormal]; compButton.titleLabel.textColor = [UIColor blueColor]; [compButton setTitleColor:self.view.tintColor forState:UIControlStateNormal]; [compButton addTarget:self action:@selector(completeCurrentWord:) forControlEvents:UIControlEventTouchUpInside]; [keyboardinputAccessoryView addSubview:compButton]; } return keyboardinputAccessoryView; }

keyboardinputAccessoryView只是一个UIView

@property (readonly, retain) UIView *keyboardinputAccessoryView;

然后制作' CustominputAccessoryView'作为textField的inputAccessoryView

    - (void)textFieldDidBeginEditing:(UITextField *)textField 
{
 textField.inputAccessoryView = [self CustominputAccessoryView];
}