UIToolbar被隐藏了

时间:2012-05-04 08:21:04

标签: iphone ios ios4 uitoolbar

我创建了UIToolbar control.which作为setInputAccessoryView添加到一个UITextField Control.Which工作正常。当点击UITextField.Up时,收费栏会出现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];
    }

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

你尝试使用静态工具栏我觉得这对你来说很容易。我从setinputview删除之前没有完成,因为没有删除set input视图的方法。