简体   繁体   中英

UIBarButtonItems of a UIToolbar hiding when presenting UIActivityViewController

隐藏按钮 This looks like a bug to me, but maybe someone can think of a workaround?

Basically if you have a custom UIToolbar , its button items will automatically hide when you present a UIActivityViewController , and reappear when you dismiss it. This is only the case on the iPhone. Being that UIActivityViewController doesn't hide the entire screen it just looks weird that buttons disappear behind the dimmed screen.

To replicate, simply start a single view project and use the following code on the view controller:

- (void)viewDidLoad {
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(didTapAction)];
    toolbar.items = [NSArray arrayWithObject:button];
    [self.view addSubview:toolbar];
}

- (void)didTapAction {
    NSArray *items = [NSArray arrayWithObjects:@"Text", nil];
    UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    [self presentViewController:sharing animated:YES completion:nil];
}

Found a workaround. Simply get rid of all the items before presenting, and add them back right after.

- (void)didTapAction {
    NSArray *items = [NSArray arrayWithObjects:@"Text", nil];
    UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
    NSArray *barItems = toolbar.items;
    toolbar.items = nil;
    [self.navigationController presentViewController:sharing animated:YES completion:nil];
    toolbar.items = barItems;
}

know it is quite old thread for but those who look this page for solution, here you go :

With iOS7, you can use this approach to show/hide your toolbar button :

if(// your code Condition) 

{ self.toolbarBtn1.enabled = YES; self.toolbarBtn1.tintColor = nil; } else { self.toolbarBtn1.enabled = NO; self.toolbarBtn1.tintColor = [UIColor clearColor]; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM