2014-01-10 12 views
8

私はUIInputView入力アクセサリビューを持つテキストフィールドを持っています。キーボードのアニメーション中にUIInputViewの背景が見えない

テキストフィールドをタップすると、キーボードが表示されて、アクセサリビューのサブビューが表示されますが、背景が表示されません。 キーボードアニメーションが完了すると、UIInputViewの背景が表示されます。

キーボードアニメーションがまだ進行中のときにUIInputViewの背景を表示させるにはどうすればよいですか?

UIInputView *inputView = [[UIInputView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,     CGRectGetWidth(self.bounds), 44.0f) inputViewStyle:UIInputViewStyleKeyboard]; 

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; 
button.frame = CGRectInset(inputView.bounds, 15.0f, 2.0f); 
[button setTitle:@"Button" forState:UIControlStateNormal]; 
[inputView addSubview:button]; 

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.bounds), 44.0f)]; 
textField.inputAccessoryView = inputView; 
[self addSubview:textField]; 
+0

こちらの回答もご覧ください。これは本当に邪魔です。 –

答えて

1

完全なソリューションではありませんが、あなたは-viewDidLoad:メソッドの内部で手動UIInputViewの背景を設定している場合、この影響を最小限に抑えることができます。

は、ここに私のコードです。幸いにも、後にそれを削除する必要はありません。表示された直後にUIInputViewは本当にキーボードの背景とぼかし効果を持っています。

UIColor *tmpBackground; //Keyboard have color base on the current device. 
if ([UIDevice isPad] || (UIDevice isPod)]) { //These are my helpers, you have to implement it 
    tmpBackground = [UIColor colorWithRed:207/255.0f green:210/255.0f blue:214/255.0f alpha:1]; 
} else { 
    tmpBackground = [UIColor colorWithRed:216/255.0f green:219/255.0f blue:223/255.0f alpha:1]; 
} 
[textField.inputAccessoryView setBackgroundColor:tmpBackground]; 

P.S.と私は知っている、それは完璧なソリューションは、このような愚かな方法で色を定義することはできません。

関連する問題