1

我正在学习 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;
}
4

3 回答 3

4

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

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

于 2010-08-06T04:55:07.820 回答
1

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

于 2012-06-28T10:42:48.027 回答
0

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

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

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

谢谢!

于 2014-11-14T20:16:09.313 回答