アプリケーションで次のようなキーボードを使用したいと思います。
これを実現する方法は?いくつかのコマンドで行を追加する方法は?
inputAccessoryView
に を実装してボタンを追加しますUIResponder
。
私がやったことは、ゼロからキーボードを作成することでした。UIViews
下部にある Fist ビューで2 つのボタンとボタンを使用します。これらのボタンでユーザー操作を無効に設定してから、次のコードを使用します。
-(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;
}
}
必要なのは、2 つIBOutlets
のビューkeyboardTextView
とキーボード ビューだけです。私のキーボードが見えるように、いくつかのファイルをアップロードします。したがって、最初のビューは、押したボタン、ボタンの背景にある画像です。2 番目のビューは、強調表示されたボタンです。そのコードを実装して 2 つを接続するとIBOutlets
、キーボードのように動作します。認識されない変数は、.h
. ボタンが押されたときに、それらを強調表示して、画像を次のように変更しました。
に :
そして、画像の上の拡大されたボタンは次のようになります。
ボタンを好きなように配置し、その上に拡大ボタンを配置するだけです。拡大されたボタン ビューが表示されますが、内部のすべてのボタンは押すまで非表示になります。私のコードがお役に立てば幸いです。自分でストーリーボードを作成する必要があります。