我想在我的应用程序中使用这样的键盘:
如何实现这一点?如何添加具有几个突击队的行?
inputAccessoryView
通过实现for 来添加按钮UIResponder
。
我所做的是从头开始创建一个键盘。UIViews
在底部的拳头视图中使用两个和按钮。在这些按钮上设置禁用用户交互,然后在此处使用此代码:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:keyboardView];
//here loops all labels
for(UIButton *keyButton in keyboardView.subviews){
if (CGRectContainsPoint(keyButton.frame,touchPoint)&&keyButton.enabled) {
keyButton.highlighted = YES;
for(UIButton *bigKey in keyboardTextView.subviews){
if (bigKey.currentTitle==keyButton.currentTitle) {
bigKey.hidden=NO;
}
else{
bigKey.hidden=YES;
}
}
}
else if(!CGRectContainsPoint(keyButton.frame,touchPoint)){
keyButton.highlighted = NO;
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:keyboardView];
//here loops all labels
for(UIButton *keyButton in keyboardView.subviews){
if (CGRectContainsPoint(keyButton.frame,touchPoint)&&keyButton.enabled) {
keyButton.highlighted = YES;
for(UIButton *bigKey in keyboardTextView.subviews){
if (bigKey.currentTitle==keyButton.currentTitle) {
bigKey.hidden=NO;
}
else{
bigKey.hidden=YES;
}
}
}
else if(!CGRectContainsPoint(keyButton.frame,touchPoint)){
keyButton.highlighted = NO;
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:keyboardView];
for(UIButton *keyButton in keyboardView.subviews){
keyButton.highlighted = NO;
if(CGRectContainsPoint(keyButton.frame,touchPoint) && keyButton.enabled == YES){
keyButton.enabled = NO;
letterUsedString=keyButton.currentTitle;
// right here you can use the letter Used String.
}
}
for(UIButton *bigKey in keyboardTextView.subviews){
bigKey.hidden=YES;
}
}
您只需要两个IBOutlets
视图keyboardTextView
和键盘视图。我将上传一些文件,以便您可以看到我的键盘。所以第一个视图是您按下的按钮,按钮背景中的图像。第二个视图是突出显示的按钮。如果您实现该代码并将两者连接起来IBOutlets
,它将像键盘一样工作。任何无法识别的变量都会添加到您的.h
. 当我按下按钮时,我突出显示了它们,这改变了图像:
到 :
然后我在图片上方的放大按钮将是:
只需按您想要的方式放置按钮,然后将放大的按钮放在上方。放大的按钮视图是可见的,但在您按下之前,里面的所有按钮都是隐藏的。我希望我的代码有帮助,你必须自己做故事板。