|  | @@ -11,12 +11,14 @@
 | 
	
		
			
			| 11 | 11 |  @interface RCCCustomTitleView ()
 | 
	
		
			
			| 12 | 12 |  @property (nonatomic, strong) UIView *subView;
 | 
	
		
			
			| 13 | 13 |  @property (nonatomic, strong) NSString *subViewAlign;
 | 
	
		
			
			|  | 14 | +@property float initialWidth;
 | 
	
		
			
			| 14 | 15 |  @end
 | 
	
		
			
			| 15 | 16 |  
 | 
	
		
			
			| 16 | 17 |  @implementation RCCCustomTitleView
 | 
	
		
			
			| 17 | 18 |  
 | 
	
		
			
			| 18 | 19 |  
 | 
	
		
			
			| 19 | 20 |  -(instancetype)initWithFrame:(CGRect)frame subView:(UIView*)subView alignment:(NSString*)alignment {
 | 
	
		
			
			|  | 21 | +    _initialWidth = frame.size.width;
 | 
	
		
			
			| 20 | 22 |      self = [super initWithFrame:frame];
 | 
	
		
			
			| 21 | 23 |      
 | 
	
		
			
			| 22 | 24 |      if (self) {
 | 
	
	
		
			
			|  | @@ -52,4 +54,56 @@
 | 
	
		
			
			| 52 | 54 |      }
 | 
	
		
			
			| 53 | 55 |  }
 | 
	
		
			
			| 54 | 56 |  
 | 
	
		
			
			|  | 57 | +- (void)setFrame:(CGRect) frame {
 | 
	
		
			
			|  | 58 | +    float referenceWidth = [self statusBarWidth];
 | 
	
		
			
			|  | 59 | +    if (referenceWidth == 0) {
 | 
	
		
			
			|  | 60 | +        referenceWidth = _initialWidth;
 | 
	
		
			
			|  | 61 | +    }
 | 
	
		
			
			|  | 62 | +    float newNavBarWidth = frame.size.width;
 | 
	
		
			
			|  | 63 | +    BOOL frameNeedsToBeCorrected = newNavBarWidth < referenceWidth || CGRectEqualToRect(self.frame, CGRectZero);
 | 
	
		
			
			|  | 64 | +
 | 
	
		
			
			|  | 65 | +    if (frameNeedsToBeCorrected) {
 | 
	
		
			
			|  | 66 | +        // first we need to find out the total point diff of the status bar and the nav bar
 | 
	
		
			
			|  | 67 | +        float navBarHorizontalMargin = referenceWidth - newNavBarWidth;
 | 
	
		
			
			|  | 68 | +        
 | 
	
		
			
			|  | 69 | +        CGRect correctedFrame = frame;
 | 
	
		
			
			|  | 70 | +
 | 
	
		
			
			|  | 71 | +        // then we need to place the nav bar half times the horizontal margin to the left
 | 
	
		
			
			|  | 72 | +        correctedFrame.origin.x = -(navBarHorizontalMargin / 2);
 | 
	
		
			
			|  | 73 | +        
 | 
	
		
			
			|  | 74 | +        // and finally set the width so that it's equal to the status bar width
 | 
	
		
			
			|  | 75 | +        correctedFrame.size.width = referenceWidth;
 | 
	
		
			
			|  | 76 | +        
 | 
	
		
			
			|  | 77 | +        [super setFrame:correctedFrame];
 | 
	
		
			
			|  | 78 | +    } else if (frame.size.height != self.frame.size.height) { // otherwise
 | 
	
		
			
			|  | 79 | +        // if only the height has changed
 | 
	
		
			
			|  | 80 | +        CGRect newHeightFrame = self.frame;
 | 
	
		
			
			|  | 81 | +        // make sure we update just the height
 | 
	
		
			
			|  | 82 | +        newHeightFrame.size.height = frame.size.height;
 | 
	
		
			
			|  | 83 | +        [super setFrame:newHeightFrame];
 | 
	
		
			
			|  | 84 | +    }
 | 
	
		
			
			|  | 85 | +    
 | 
	
		
			
			|  | 86 | +    // keep a ref to the last frame, so that we avoid setting the frame twice for no reason
 | 
	
		
			
			|  | 87 | +//    _lastFrame = frame;
 | 
	
		
			
			|  | 88 | +}
 | 
	
		
			
			|  | 89 | +
 | 
	
		
			
			|  | 90 | +
 | 
	
		
			
			|  | 91 | +- (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
 | 
	
		
			
			|  | 92 | +    // whenever the orientation changes this runs
 | 
	
		
			
			|  | 93 | +    // and sets the nav bar item width to the new size width
 | 
	
		
			
			|  | 94 | +    CGRect newFrame = self.frame;
 | 
	
		
			
			|  | 95 | +
 | 
	
		
			
			|  | 96 | +    if (newFrame.size.width < size.width) {
 | 
	
		
			
			|  | 97 | +        newFrame.size.width = size.width;
 | 
	
		
			
			|  | 98 | +        newFrame.origin.x = 0;
 | 
	
		
			
			|  | 99 | +    }
 | 
	
		
			
			|  | 100 | +    [super setFrame:newFrame];
 | 
	
		
			
			|  | 101 | +}
 | 
	
		
			
			|  | 102 | +
 | 
	
		
			
			|  | 103 | +-(float) statusBarWidth {
 | 
	
		
			
			|  | 104 | +    CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
 | 
	
		
			
			|  | 105 | +    return MAX(statusBarSize.width, statusBarSize.height);
 | 
	
		
			
			|  | 106 | +}
 | 
	
		
			
			|  | 107 | +
 | 
	
		
			
			|  | 108 | +
 | 
	
		
			
			| 55 | 109 |  @end
 |