没有键盘的TextView上的AccessoryView?

时间:2010-08-05 18:02:43

标签: iphone ipad uitextview uikeyboard accessoryview

我正在学习AccessoryViews并测试Apple示例:KeyBoardAccessory

我正在尝试显示避免键盘显示的配件视图,但我不能这样做: - (

我在textViewShouldBeginEditing中返回NO以避免键盘并在返回之前动画调整TextView的大小,但没有任何反应。

我做错了什么?

- (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.
        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;
}

3 个答案:

答案 0 :(得分:4)

inputAccessoryView用于在标准Apple虚拟键盘上方显示视图。如果您不允许出现屏幕键盘,则inputAccessoryView也不会出现。

如果您只想显示自定义键盘,而不是标准的屏幕键盘,则应使用inputView而不是inputAccessoryView。在这里查看inputView和inputAccessoryView之间的区别: http://developer.apple.com/iphone/library/documentation/uikit/reference/UITextView_Class/Reference/UITextView.html

答案 1 :(得分:1)

如果您真的只想要一个配件视图,则必须将输入视图设置为没有高度的视图。

答案 2 :(得分:0)

在Xcode 6上,ios 8.1 Simulator默认显示隐藏的键盘。 (我必须选择“切换软件键盘”才能显示它。)

我喜欢这个,因为只有我的附件出现。

我有办法以编程方式重现(打开和关闭键盘,不解除)

谢谢!