0

我创建了 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];
    }
4

2 回答 2

0

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

于 2012-05-04T08:46:09.327 回答
0

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

于 2012-05-04T08:30:42.863 回答