【问题标题】:UIToolbar is getting hiddenUIToolbar 被隐藏
【发布时间】:2012-05-13 18:51:21
【问题描述】:

我创建了 UIToolbar 控件。它作为 setInputAccessoryView 添加到一个 UITextField 控件中。效果很好。点击 UITextField 时收费栏会出现 uikeyboard。到此为止没有问题。

当我放置一个按钮时,点击它时我想隐藏键盘,只想显示工具栏。

这没有发生。工具栏被隐藏了。

请告诉我,代码中的问题/原因是什么。

感谢您的宝贵时间。

- (void)viewDidLoad {

 [super viewDidLoad];

        //
        myToolbar = [[UIToolbar alloc] init];
        [myToolbar sizeToFit];
        myToolbar.frame = CGRectMake(0,198, 320, 35);
        myToolbar.barStyle = UIBarStyleBlackTranslucent;
        [self.view addSubview:myToolbar];


        UIImage *image = [UIImage imageNamed:@"orangebuttonsmall.png"];
        UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aButton.frame = CGRectMake(0, 100, image.size.width, 25 );    
        aButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [aButton setTitle:@"Tap" forState:UIControlStateNormal];
        [aButton setBackgroundImage: image forState:UIControlStateNormal];
        [aButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        aButton.titleLabel.font = [UIFont boldSystemFontOfSize:10];
        [aButton addTarget:self action:@selector(aCenterBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
         [self.view addSubview:aButton];


        myToField = [[UITextField alloc] init];
        myToField.frame = CGRectMake(0, 0, 320, 48);
        myToField.textColor = [UIColor blackColor]; //text color
        myToField.font = [UIFont systemFontOfSize:17.0];  //font size
        myToField.placeholder = @"To:";  //place holder
        myToField.backgroundColor = [UIColor whiteColor]; //background color
        myToField.autocorrectionType = UITextAutocorrectionTypeNo;  // no auto correction support
        myToField.keyboardType = UIKeyboardTypePhonePad;  // type of the keyboard
        myToField.returnKeyType = UIReturnKeyDone;  // type of the return key
        myToField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [myToField setInputAccessoryView:myToolbar];
        myToField.textAlignment = UITextAlignmentLeft;
        [myToField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];

        myToField.rightViewMode=UITextFieldViewModeAlways;
        // has a clear 'x' button to the right
        myToField.delegate = self;  
        [myToField becomeFirstResponder];
        [self.view addSubview:myToField];

     }

    -(void)aCenterBtnClicked:(id)sender{

        [myToField resignFirstResponder];

        myToolbar.frame = CGRectMake(0,198, 320, 35);
        myToolbar.barStyle = UIBarStyleBlackTranslucent;
        [self.view addSubview:myToolbar];
    }

【问题讨论】:

    标签: iphone ios ios4 uitoolbar


    【解决方案1】:

    inputAccessoryViews 作为子视图放置在 UIKeyboard 上,如果隐藏键盘,它会隐藏 inputAccessoryView。尝试将工具栏添加为 self.view 的子视图,并在显示键盘时通过订阅 UIKeyboardWillShow 通知并从 userInfo 中拉动动画持续时间来为其位置设置动画。

    【讨论】:

      【解决方案2】:

      你尝试静态工具栏,我认为这对你来说很容易。在从 setinputview 删除之前我没有完成,因为没有删除设置输入视图的方法。

      【讨论】:

        猜你喜欢
        • 2011-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-21
        • 1970-01-01
        相关资源
        最近更新 更多