2016-03-24 7 views
0

Meine App Die meisten Seiten sind Landschaft, nur ein paar Seiten sind Portrait. Image zeigt mein Problem. Im Fall von Hochformat ist die Position der Symbolleiste über Tastatur/Datumsauswahl nicht korrekt. Ich Geräteausrichtung eingestellt sind, Porträt/Landschaft links/Landschaft rechts. Und in Portrait Seite meinen CodeiOS-Symbolleiste über Tastaturposition nicht korrekt

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

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

- (BOOL)shouldAutorotate{ 
    return YES; 
} 

Die Folge sind meine Symbolleiste 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]; 
    self.babyBirthdayTextfield.inputAccessoryView=toolbar; 

Das Problem trat auch auf Web-Ansicht my app Portrait view's structure

ich das Problem behoben haben. Der Hauptcontroller dieses Storyboards ist ein modales Fenster. Ändern der Art des Segments

+0

Bitte fügen Sie weiteren Code in Bezug auf, wie Sie Ihre Tastatur hinzufügen – atulkhatri

Antwort

0

Sie müssen den Rahmen der Symbolleiste nicht manuell verwalten. Verwenden Sie einfach die Textfield inputAccessoryView und Sie sind gut zu gehen:

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)], 
         nil]; 
[toolbar sizeToFit]; 
self.textField.inputAccessoryView = toolbar; 

Hoffnung, das hilft.

+0

Entschuldigung, das ist nicht funktionieren. – Dongqing

+0

Welches Problem haben Sie, wenn Sie diesen Code verwenden? – atulkhatri

+0

Ich habe Ihren Code verwendet, das Problem trat auch auf. – Dongqing