Here is a code I use for drawing mask for UIView. The problem is that if I have more than 5 UIViews with mask on the screen it influence performance when drag & drop UIViews: How can I improve the code below?:
+ (UIBezierPath *)roundedPathAtCenter:(CGPoint)center size:(CGSize)size corner:(CGFloat)corner
{
NSInteger width = size.width;
NSInteger height = size.height;
UIBezierPath *path = [UIBezierPath bezierPath];
// upper left corner
[path moveToPoint: CGPointMake(center.x - width / 2.0f + corner / 2.0f, center.y - height / 2.0f + corner / 2.0f)];
// path to top center
[path addQuadCurveToPoint: CGPointMake(center.x, center.y - height / 2.0f) controlPoint: CGPointMake(center.x - width / 2.0f + corner, center.y - height / 2.0f)];
// path to upper right
[path addQuadCurveToPoint: CGPointMake(center.x + width / 2.0f - corner / 2.0f, center.y - height / 2.0f + corner / 2.0f) controlPoint: CGPointMake(center.x + width / 2.0f - corner, center.y - height / 2.0f)];
// path to mid right
[path addQuadCurveToPoint: CGPointMake(center.x + width / 2.0f, center.y) controlPoint: CGPointMake(center.x + width / 2.0f, center.y - height / 2.0 + corner)];
// path to lower right
[path addQuadCurveToPoint: CGPointMake(center.x + width / 2.0 - corner / 2.0f, center.y + height / 2.0f - corner / 2.0f) controlPoint: CGPointMake(center.x + width / 2.0f, center.y + height / 2.0f - corner)];
// path to center bottom
[path addQuadCurveToPoint: CGPointMake(center.x, center.y + height / 2.0f) controlPoint: CGPointMake(center.x + width / 2.0 - corner, center.y + height / 2.0)];
// path to lower left
[path addQuadCurveToPoint: CGPointMake(center.x - width / 2.0f + corner / 2.0f, center.y + height / 2.0f - corner / 2.0f) controlPoint: CGPointMake(center.x - width / 2.0f + corner, center.y + height / 2.0f)];
// path to mid left
[path addQuadCurveToPoint: CGPointMake(center.x - width / 2.0f, center.y) controlPoint: CGPointMake(center.x - width / 2.0f, center.y + height / 2.0 - corner)];
// path to top left
[path addQuadCurveToPoint: CGPointMake(center.x - width / 2.0f + corner / 2.0f, center.y - height / 2.0f + corner / 2.0f) controlPoint: CGPointMake(center.x - width / 2.0f, center.y - height / 2.0f + corner)];
[path closePath];
return path;
}
Without adding mask for UIViews it works very fast