OGeek|极客世界-中国程序员成长平台

标题: ios - 输入附件 View 显示在 UIAlertController 等对象上 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:07
标题: ios - 输入附件 View 显示在 UIAlertController 等对象上

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

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



Best Answer-推荐答案


这将解决..!

不要使用名称'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 actionselector(completeCurrentWord forControlEvents:UIControlEventTouchUpInside]; [keyboardinputAccessoryView addSubview:compButton]; } 返回键盘输入附件 View ; }

keyboardinputAccessoryView 只是一个 UIView

@property (readonly, retain) UIView *keyboardinputAccessoryView;

然后将'CustominputAccessoryView'作为你的textField的inputAccessoryView

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

关于ios - 输入附件 View 显示在 UIAlertController 等对象上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40758324/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4