iOS toolbar above keyboard position not correct

My App Most of pages is Landscape, only a few pages are Portrait. Image shows my problem. In the case of Portrait, the position of the toolbar above keyboard/date-picker is not correct. I set device orientations are Portrait/Landscape Left/Landscape Right. And in Portrait page my code

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    if ([NSObject isiPhone]) {
        return UIInterfaceOrientationPortrait;
    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    if ([NSObject isiPhone]) {
        return UIInterfaceOrientationMaskPortrait;
    return UIInterfaceOrientationMaskLandscape;

- (BOOL)shouldAutorotate{
    return YES;

The follow are my toolbar code:

    UIToolbar *toolbar=[[UIToolbar alloc]init]; 
    toolbar.barTintColor=[UIColor lightTextColor]; 
    toolbar.frame=CGRectMake(0, 0, 320, 44); 
    UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"OK" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
    toolbar.items = @[item2,item3]; 

The issue also occurred on web view my app Portrait view's structure

I have fixed the problem. The root controller of this storyboard is a modal window. Changing the segue's kind.


You don't have to manage frame of the toolbar manually. Just use textField's inputAccessoryView and you are good to go:

UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonTapped)],
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped)],
[toolbar sizeToFit];
self.textField.inputAccessoryView = toolbar;

Hope this helps.

Need Your Help

Change the value of a bound property on an existing item in iron-list

javascript polymer polymer-1.0

I have an item bound in my iron-list, when I change a bound property on the object I am expecting to see the change reflected on the screen, but I don't. What am doing wrong?

Relational Database for genetic variation

database-design bioinformatics django-database

I am trying to represent to genetic variation data in a database for my institution. We have discovered genetic variants, which have associated with them reference alleles, mutant alleles, chromoso...