0

Je suis confronté à un problème étrange lors de l'exécution de l'application en utilisant Xcode 9 sur iOS 11.J'ai à montrer le bouton Annuler dans la barre de navigation droite pour revenir sur le contrôleur parent.Il était fonctionne bien jusqu'à iOS 10.3.ImagePickerController sur iOS 11 ne montre pas rightBarButton Mais il fonctionne sur le taraudage

J'ai essayé de régler la couleur de la barre de navigation & .topItem.rightBarButtonItem. Lorsque vous manipulez les méthodes de délégation de navigation, le bouton Annuler devient visible lorsque nous sélectionnons un album &.

est le code ici, je l'ai utilisé pour montrer le bouton annuler

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

J'ai essayé avec viewWillLayoutSubviews prépondérants dans l'extension UIImagePickerController

@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]; 

    } 

S'il vous plaît aidez-moi ce que je peux faire d'autre faites-le fonctionner comme avant.

J'ai pris une capture d'écran lorsque je tapais en haut à droite, puis ce bouton d'annulation devient visible. enter image description here

+0

Le 'UIImagePickerController' a un bouton d'annulation, pourquoi devez-vous le remplacer? – Bannings

+0

Mais ce n'est pas visible maintenant. Donc, après avoir dépassé au moins je peux voir cela tout en avançant/revenant. – Ellen

+1

Peut-être que vous utilisez UIAppereance quelque part dans l'application –

Répondre

0

Merci pour vos précieuses réponses. J'ai été en mesure de résoudre le problème en supprimant le code d'apparence UIBarButtonItem de UINavigationController sous-classe & utilisé avec le bouton personnalisé de réglage.