I use this code to round one corner of my UIView :
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.view.bounds byRoundingCorners:(UIRectCornerTopLeft) cornerRadii: CGSizeMake(10.0, 10.0)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.view.bounds; maskLayer.path = maskPath.CGPath; self.view.layer.mask = maskLayer; self.view.layer.masksToBounds = NO;
This code works if I never resize the view. If I make the view larger, a new area will not appear because it extends beyond the mask layer (this mask layer does not automatically resize with the view). I could just make the mask as big as it will ever be, but it can be full-screen on the iPad, so I'm worried about performance with a big mask (I will have more than one of them in my UI). In addition, the ultra-small mask will not work for a situation where I need the upper right corner (one) to be rounded.
Is there a simpler and easier way to achieve this?
Update : this is what I'm trying to achieve: http://i.imgur.com/W2AfRBd.png (the rounded corner I want is surrounded by green).
I got a working version of this using a subclass of UINavigationController and overriding viewDidLayoutSubviews as follows:
- (void)viewDidLayoutSubviews { CGRect rect = self.view.bounds; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(8.0, 8.0)]; self.maskLayer = [CAShapeLayer layer]; self.maskLayer.frame = rect; self.maskLayer.path = maskPath.CGPath; self.view.layer.mask = self.maskLayer; }
Then I create an instance of the UINavigationController subclass with my view controller, and then I shift the view frame of the controller controller by 20px (y) to open the status panel and leave the panel with a high resolution of 44 pixels, as shown in the image.
The code works, except that it does not handle rotation at all. When the application rotates, viewDidLayoutSubviews is called before the rotation, and my code creates a mask that matches the view after the rotation; this creates an unwanted rotation lock when the bit to be hidden is displayed during rotation. In addition, while the rotation of the application is completely smooth without this mask, when you create the mask, the rotation becomes noticeably jerky and slow.
The Evomail iPad app also has rounded corners like this, and their app suffers from the same issue.