0

I have created UIToolbar control.which is added as setInputAccessoryView to one UITextField Control.Which works fine. the tollbar comes up with uikeyboard when tapping UITextField.Up to this no issues.

When i placed one button, when tapping on it i want to hide the keyboard and only want to display the toolbar.

This is not happening.the toolbar is getting hidden.

Please let me know , what is the problem/ reason in the code.

Thanks for your time.

- (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];
    }
iamsult
  • 1,581
  • 1
  • 15
  • 21
user198725878
  • 6,266
  • 18
  • 77
  • 135

2 Answers2

0

inputAccessoryViews are placed as a subview on the UIKeyboard, if you hide the keyboard, it will hide the inputAccessoryView. Try adding the toolbar as a subview of self.view and animate it's position up when the keyboard is displayed by subscribing to the UIKeyboardWillShow notification and pulling the animation duration from the userInfo.

Jesse Gumpo
  • 4,777
  • 1
  • 20
  • 29
0

You try for static toolbar i think that will be easy for you.I am not done before remove from setinputview because there is no method for remove set input view.

vishiphone
  • 750
  • 7
  • 14