2012-05-04 118 views
0

我創建了UIToolbar control.which作爲setInputAccessoryView添加到一個UITextField Control.Which工作正常。當點擊UITextField.Up時,toll​​bar會出現uikeyboard。UIToolbar被隱藏

當我放置一個按鈕,當點擊它時,我想隱藏鍵盤,只想顯示工具欄。

這不會發生,工具欄正在隱藏。

請讓我知道,代碼中的問題/原因是什麼。

謝謝你的時間。

- (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]; 
    } 

回答

0

inputAccessoryViews放置爲在UIKeyboard一個子視圖,如果你隱藏鍵盤,它會隱藏inputAccessoryView。嘗試添加工具欄作爲self.view的子視圖,並通過訂閱UIKeyboardWillShow通知並從userInfo中拉動動畫持續時間來顯示鍵盤時將其定位。

0

您嘗試使用靜態工具欄,我認爲這對您很簡單。我之前沒有做過從setinputview中刪除的工作,因爲沒有用於刪除set input view的方法。