【问题标题】:AccessoryView on TextView without Keyboard?没有键盘的TextView上的AccessoryView?
【发布时间】:2011-03-25 23:11:08
【问题描述】:

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

【问题讨论】:

  • 您能否更深入地解释您想要获得的结果?当您单击文本视图而不是键盘和附件视图时,您希望只显示与键盘关联的附件视图?
  • 是的,我只想显示附件,但是我对要使用的属性有误,我需要一个 inputView

标签: iphone ipad uitextview uikeyboard accessoryview


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    如果你真的只想要一个辅助视图,你必须将输入视图设置为没有高度的视图。

    【讨论】:

      【解决方案3】:

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

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

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

      谢谢!

      【讨论】:

        猜你喜欢
        • 2010-12-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-08
        • 1970-01-01
        • 2011-11-01
        • 2012-01-13
        • 2016-07-02
        • 1970-01-01
        相关资源
        最近更新 更多