【问题标题】:Input Accessory View is showing over objects like UIAlertController输入附件视图显示在 UIAlertController 等对象上
【发布时间】:2017-04-07 02:24:20
【问题描述】:

我正在通过以下方式使用输入附件视图。

override var canBecomeFirstResponder: Bool {
    return true
}

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

另外,在 viewDidAppear 方法中,我说:

let _ = self.becomeFirstResponder()

在我的情况下这是必须的,因为我的 viewController 是 childViewController。

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

有人经历过类似的事情吗?

谢谢

编辑 - 添加图片:

【问题讨论】:

  • 发图就容易理解了
  • 您找到解决方案了吗?

标签: ios swift inputaccessoryview


【解决方案1】:

这将解决..!

不要使用名称'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];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    • 1970-01-01
    相关资源
    最近更新 更多