Note that there are some explanatory texts on larger screens.

plurals
  1. POMaster-Details SplitViewController Custom UINavigationBar
    primarykey
    data
    text
    <p>I have a Master-Details project setup and running in XCode with no problems at all and everything works fine. However, when I attempt to round the top right and left corners of the NavigationBar it has a very strange effect. It basically, offsets the 'touch' response of the 'back' left button on the details view.</p> <p>The button still works, but it seems that the iPhone can only pick up the user's touch when they click just below the NavigationBar and not the button itself.</p> <p>The code I have is:</p> <pre><code>// Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { UIColor *color = [UIColor darkGrayColor]; UIImage *img = [UIImage imageNamed:@"nav-bar"]; [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; self.tintColor = color; // Create mask to round corners CGRect bounds = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; // Apply mask to navigation bar [self.layer addSublayer:maskLayer]; self.layer.mask = maskLayer; // Apply logo to navigation bar UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]]; self.topItem.titleView = imageView; } </code></pre> <p>Here is a screen shot of what I mean, button only responses when I touch where the arrow is pointing:</p> <p><img src="https://i.stack.imgur.com/lXtUK.png" alt="Touch Point"></p> <p>--- UPDATE ---</p> <p>After some testing I've worked out the problem is with the 'self.layer.mask = maskLayer' line. I have refactored the code and tested in another project that just uses xib files and not story boards, and dont have any problems, but its still not working in the current project.</p> <pre><code>CGRect bounds = CGRectMake(0, 0, navigationController.navigationBar.bounds.size.width, navigationController.navigationBar.bounds.size.height); UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) cornerRadii:CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = bounds; maskLayer.path = maskPath.CGPath; // Apply mask to navigation bar //navigationController.navigationBar.layer.mask = maskLayer; [navigationController.navigationBar.layer addSublayer:maskLayer]; navigationController.navigationBar.layer.mask = maskLayer; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload