UINavigationBar background image via drawRect - problem with fast animation

I am adding a custom background image to my UINavigationBar, overriding drawRect through the category.

- (void) drawRect :( CGRect) rect {
    [[UIImage imageNamed: @ "navbar.png"] drawInRect: CGRectMake (0, self.frame.size.height-44, self.frame.size.width, 44)];
}

This solution works fine until you try to use the navigationitem.prompt property. Instead of making smooth animation of the presentation of the invitation, she does it all of a sudden.

Are there any suggestions on how to fix this? Or an alternative way to set the background image.

PS. I am trying to avoid adding a background image as a subquery due to things being rebuilt when view push / pop. And I would not want to send SubviewToBack to every viewDidAppear view.

TIA!

EDIT: I also tried the swizzling method, which would work just fine if I could just let my image stretch, but since the image is not stretched, I need to figure out how to use the animation that happens to make the shift instead of stretching.

EDIT: see my hacker answer below

+3
source share
1 answer

So very “hacked”, but it’s the closest that I can get him to do what I want ...

, swizzling, , . img , .

, .

#import "UINavigationBar+custom.h"

#define cornersTag 1

@implementation UINavigationBar (UINavigationBarCategory)

-(void)setCornersIfNeeded{
 UIImageView *corners = (UIImageView*)[self viewWithTag:cornersTag];
 if(!corners){
  UIImage *img = [[UIImage imageNamed:@"navbar_corners.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];
  corners = [[[UIImageView alloc] initWithImage:img] autorelease];
  corners.frame = CGRectMake(0, 0, self.frame.size.width, img.size.height);
  corners.tag = cornersTag;
  [self addSubview:corners];
 }
}

- (void)customDrawRect:( CGRect )rect{
 [self customDrawRect:rect];
 [[UIImage imageNamed:@"navbar.png"] drawInRect:rect]; 
 [self setCornersIfNeeded];
}

@end

swizzling... http://www.cocoadev.com/index.pl?MethodSwizzling Swizzle iPhone

0

Source: https://habr.com/ru/post/1720996/


All Articles