UIViewController-BackButtonHandler icon indicating copy to clipboard operation
UIViewController-BackButtonHandler copied to clipboard

A little problem for custom back button

Open wonderffee opened this issue 9 years ago • 3 comments

If custom back button is used, pressing back button may cause redisplay of default back button(iOS 8.1, iPhone6). So for this case, "subview.alpha = 1.;" is not necessary.

wonderffee avatar Sep 11 '15 02:09 wonderffee

Probably this is fixed by 834617d ?

onegray avatar Feb 13 '16 15:02 onegray

因为是自定义按钮 所以不会调用- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item 所以你的框架就没有用了

pusswzy avatar Sep 07 '17 14:09 pusswzy

I had the same issue this was the solution for me. When using custom image for your back button, iOS does not remove the actual back button, it only fades to to alpha 0. And the interception function was re-seting the back button to 1.

If you customized the back button globally like this:

UIImage *backbutton= [[UIImage tintableImageNamed:@"back-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeTile];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backbutton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

Then you should add this in : - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item

BOOL hasCustomImage = [[UIBarButtonItem appearance] backButtonBackgroundImageForState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        if (!hasCustomImage) {
             // Workaround for iOS7.1. Thanks to @boliva - http://stackoverflow.com/posts/comments/34452906
            for(UIView *subview in [navigationBar subviews]) {
                if(subview.alpha < 1.) {
                    [UIView animateWithDuration:.25 animations:^{
                        subview.alpha = 1.;
                    }];
                }
            }
        }

Can you confirm that this works for you ?

polo2244 avatar Sep 17 '17 21:09 polo2244