在inputAccessoryView、UITextView或UISearchBar上添加一个饼很容易。但是,据我所知,没有明显而简单的方法为您的基本UIView添加一个!
我有一个UIView子类,它遵循UIKeyInput协议。它接收键盘输入来做与输入文本无关的事情,所以我不想强迫它对以前指定的视图进行子类,因为它会增加膨胀,并且会暴露一些不做任何事情的属性,另外,我还需要绕过那些类(更多的膨胀)出现的文本条目。
然而,我的UIView确实需要一个输入附件视图在其提供的键盘上才能正常工作。
有什么简单的方法来解决这个问题吗?我是否必须在我的UIKeyboardWillShowNotification子类中注册为UIView的观察者,并手动向其添加一个子视图,作为附件视图?
发布于 2013-12-05 22:31:59
您是否尝试简单地将inputAccessoryView方法添加到viewController中?我相信它在显示键盘时会被调用,所以您实际上不必为每个textField或视图分配一个。
- (UIView *)inputAccessoryView
{
if (!inputAccessoryView)
{
CGRect accessFrame = CGRectMake(0.0, 0.0, 768.0, 77.0);
inputAccessoryView = [[UIView alloc] initWithFrame:accessFrame];
inputAccessoryView.backgroundColor = [UIColor blueColor];
UIButton *compButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
compButton.frame = CGRectMake(313.0, 20.0, 158.0, 37.0);
[compButton setTitle: @"Word Completions" forState:UIControlStateNormal];
[compButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[compButton addTarget:self action:@selector(completeCurrentWord:) forControlEvents:UIControlEventTouchUpInside];
[inputAccessoryView addSubview:compButton];
}
return inputAccessoryView;
}https://stackoverflow.com/questions/20411999
复制相似问题