AccessoryView on TextView without Keyboard?
I'm learning about AccessoryViews and testing the Apple example: KeyBoardAccessory
I'm trying to show the accessory view avoiding the Keyboard to show, but I can't do it :-(
I'm returning NO in textViewShouldBeginEditing to avoid keyboard and animating the resize of the TextView before return, but nothing happens.
What I'm doing wrong?
- (void)viewWillAppear:(BOOL)animated {
// Make the keyboard appear when the application launches.
[super viewWillAppear:animated];
[textView becomeFirstResponder];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)aTextView {
NSLog(@"textViewShouldBeginEditing");
/*
You can create the accessory view programmatically (in code), in the same nib file as the view controller's main view, or from a separate nib file. This example illustrates the latter; it means the accessory view is loaded lazily -- only if it is required.
*/
if (textView.inputAccessoryView == nil) {
[[NSBundle mainBundle] loadNibNamed:@"AccessoryView" owner:self options:nil];
// Loading the AccessoryView nib file sets the accessoryView outlet.
textView.inputAccessoryView = accessoryView;
// After setting the accessory view for the text view, we no longer need a reference to the accessory view.
开发者_JAVA百科self.accessoryView = nil;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
textView.frame = CGRectMake(textView.frame.origin.x, textView.frame.origin.y, textView.frame.size.width, textView.frame.size.height - 100);
[UIView commitAnimations];
return NO;
}
inputAccessoryView is for a view to come up above the standard apple virtual keyboard. If you don't allow the on-screen keyboard to appear, then the inputAccessoryView will not appear either.
If you ONLY want a custom keyboard to show, and NOT the standard on-screen keyboard, you should use inputView instead of inputAccessoryView. See the difference between inputView and inputAccessoryView here: http://developer.apple.com/iphone/library/documentation/uikit/reference/UITextView_Class/Reference/UITextView.html
If you really want an accessoryview only, you have to set the inputview to a view with no height.
On Xcode 6, the ios 8.1 Simulator show the keyboard hidden by default. (I have to select "Toggle software keyboard" to have it appear.)
I love this, because only my accessoryview appear.
I there a way to reproduce this programmatically(toggle keyboard on and off, no dismiss)
Thanks!
精彩评论