TextView 上的 AccessoryView 没有键盘?

发布于 2024-09-12 21:25:20 字数 1651 浏览 5 评论 0原文

我正在学习 AccessoryViews 并测试 Apple 示例: KeyBoardAccessory< /a>

我试图显示附件视图,避免显示键盘,但我做不到:-(

我在 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;
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野の 2024-09-19 21:25:20

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

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

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

紫瑟鸿黎 2024-09-19 21:25:20

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

If you really want an accessoryview only, you have to set the inputview to a view with no height.

£冰雨忧蓝° 2024-09-19 21:25:20

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

我喜欢这个,因为只显示我的附件视图。

我有一种方法可以以编程方式重现此内容(打开和关闭键盘,不关闭)

谢谢!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文