2012-09-17 141 views

回答

1

通过为UIResponder实施inputAccessoryView来添加按钮。

+1

Thx为您的文章,我用谷歌,并找到了这个教程:http://gabriel-tips.blogspot.de/2011/05/input-accessory-view-how-to-add-extra.html –

1

我所做的是从零开始创建一个键盘。使用两个UIViews以及位于底部的Fist视图中的按钮。设置用户交互这些按钮关闭,然后用此验证码:

-(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。当我的按钮,其中按下我强调他们从改变形象:

this

到:

this

然后我上面的图像放大按钮即可:

this.

只需将你的按钮放在你想要的位置,上面的放大按钮。放大的按钮视图是可见的,但所有按钮内部都隐藏,直到您按下。我希望我的代码能够帮助你,你必须自己做故事板。

+0

'+ 1'分享你的代码和广泛的解释:) – Anne

+0

谢谢,我希望别人也能理解它,没有故事板文件的帮助。 – Comradsky

相关问题