0

Ich habe ein seltsames Problem beim Ausführen von App mit Xcode 9 auf iOS 11.Ich muss Abbrechen Schaltfläche in der Navigationsleiste anzeigen, um auf übergeordneten Controller zurück zu bewegen.Es war funktioniert gut bis iOS 10.3.ImagePickerController auf iOS 11 zeigt nicht rightBarButton Aber es funktioniert beim Tippen

Ich habe versucht mit der Einstellung Tönungsfarbe der Navigationsleiste & .topItem.rightBarButtonItem. Bei der Bearbeitung der Navigations-Delegiertenmethoden wird die Abbrechen-Schaltfläche sichtbar, wenn wir ein beliebiges Album auswählen. & kommt zur Albumansicht zurück.

hier ist der Code, sich hat Taste

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 

    //Add cancel button since it was not visible even applying tint color to imagepickerviewcontroller 
    UIButton* customButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [customButton setFrame:CGRectMake(0, 0, 80, 44)]; 
    [customButton setTitleColor:self.tintColor forState:UIControlStateNormal]; 
    [customButton.titleLabel setTextAlignment:NSTextAlignmentRight]; 
    [customButton setTitle:NSLocalizedString(@"CF_CANCEL", @"Cancel") forState:UIControlStateNormal]; 
    [customButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside]; 

    UINavigationBar *navigationBar = navigationController.navigationBar; 
    navigationBar.barStyle = UIBarStyleDefault; 
    navigationBar.tintColor = [UIColor redColor]; 
    UINavigationItem *pickerNavBarTopItem = navigationBar.topItem; 

    UIBarButtonItem *cancelBarItem = [[UIBarButtonItem alloc]initWithCustomView:customButton]; 
    pickerNavBarTopItem.rightBarButtonItem = cancelBarItem; 

} 
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated { 

    //Add cancel button since it was not visible even applying tint color to imagepickerviewcontroller 
    UIButton* customButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [customButton setFrame:CGRectMake(0, 0, 80, 44)]; 
    [customButton setTitleColor:self.tintColor forState:UIControlStateNormal]; 
    [customButton.titleLabel setTextAlignment:NSTextAlignmentRight]; 
    [customButton setTitle:NSLocalizedString(@"CF_CANCEL", @"Cancel") forState:UIControlStateNormal]; 
    [customButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside]; 

    UINavigationBar *navigationBar = navigationController.navigationBar; 
    navigationBar.barStyle = UIBarStyleDefault; 
    navigationBar.tintColor = [UIColor redColor]; 
    UINavigationItem *pickerNavBarTopItem = navigationBar.topItem; 

    UIBarButtonItem *cancelBarItem = [[UIBarButtonItem alloc]initWithCustomView:customButton]; 
    pickerNavBarTopItem.rightBarButtonItem = cancelBarItem; 
} 

- (void)cancelButtonAction{ 

    if (self.imageCompletionBlock != nil) { 
     self.imageCompletionBlock(nil, self.takePhotoOption); 

    } 
    [self.imagePickerController dismissViewControllerAnimated:YES completion:nil]; 
} 

Abbrechen zur Darstellung verwende ich mit überwiegendem viewWillLayoutSubviews in UIImagePickerController Erweiterung

@implementation UIImagePickerController (FFGNavbar) 

    -(void)viewWillLayoutSubviews 
    { 
     [super viewWillLayoutSubviews]; 
     [self.navigationBar setTintColor:[UIColor cf_themeColor]]; 
     self.navigationBar.topItem.rightBarButtonItem.tintColor = [UIColor cf_themeColor]; 
     [self.navigationBar.topItem.rightBarButtonItem setEnabled:true]; 

    } 

Bitten mir, was kann ich sonst noch tun helfen versucht haben, mach es wie früher.

Ich habe den Screenshot gemacht, als ich oben rechts angetippt habe, dann wird diese Schaltfläche zum Abbrechen sichtbar. enter image description here

+0

Der 'UIImagePickerController' hat eine Schaltfläche zum Abbrechen, warum müssen Sie ihn überschreiben? – Bannings

+0

Aber es ist jetzt nicht sichtbar. Nach dem Atleast kann ich das beim Vorwärtskommen/Zurückkommen sehen. – Ellen

+1

Vielleicht verwenden Sie UIAppeereance irgendwo in der Anwendung –

Antwort

0

Danke für wertvolle Antworten. Ich konnte das Problem beheben, indem ich den UIBarButtonItem-Code von der UINavigationController-Unterklasse & entfernte, die mit der benutzerdefinierten Einstellung verwendet wurde.

Verwandte Themen