CALayer: Maintaining cornerRadius on layer's contents - ios

I've been looking at the CALayer's documentation and it seems like cornerRadius only affects the background of the layer and not the contents.
Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit?
I've seen suggestions about masks, but that sounds costly. I've also seen suggestions about drawing the contents manually, but I don't really know where to start. I know a bit about rendering images in contexts, but I don't know how I'm supposed to draw it onto the CALayer's content view with a corner radius. The best I would know is to subclass CALayer and override the drawInContext method and use CGContextDrawImage.
All help is greatly appreciated, but to reiterate the question: "Is there a way to apply the corner radius to the entire CALayer without taking a big performance hit?"

cornerRadius does apply to the entire CALayer and it does not cause a big performance hit. If you are not seeing the contents with rounded corners, it is because you have forgotten to set masksToBounds to YES.

Related

How to make view's board like tear from the paper?

I want to make the view's board like tear from the paper(in the picture) by code ,but I don't have any idea.Please help me!
You can do something like this a UIView using CALayer’s mask property for the torn edges, and using a UIBezierPath with CALayer’s shadowPath for the shadow.
Drawing something like this with shadows and transparency will be relatively slow. Of course the other (and perhaps easier) approach would be to use a static background image created in Photoshop or something similar.
See here for details on drawing using BezierPaths
Drawing on Transparency layers

Animate color of stroke's ends using CGPath

Quick diagrams! I'm trying to implement this:
I have this working almost 100% currently (though this is a slightly different stage of the animation):
Everything looks good minus the fade effects at the end of the stroke. Is that possible using a simple CGPath? I'm animating strokeStart and strokeEnd to get the current effect. I've tried using CAGradientLayer as a mask on the layer, but that adds a gradient over the entire layer, not just the ends. Overriding drawRect isn't possible since I'm doing this dynamically with animations.
Any thoughts about how to achieve this effect? I have no idea which direction to go.
Depending on how important opacity is and how complex the rest of the animation is, one option would be to make two blurred tail objects that follow the ends of the path as it is animating.
Roundabout solution, sorry I can't think of another versatile way!

How to not scale CATextLayers when scaling super layer

My problem is:
I have a CAShapeLayer named outCircle. I add some CATextLayers as sublayers of outCircle. The problem is that when I'm pinching outCircle and doing so scale it, the sublayer CATextLayers resize too (maybe obvious) and become blurry and not crisp. The text looks horrible!
So I want to keep the original size and (maybe) position of the text layers yet keeping them sublayers of outCircle.
Is it possible?
How can I do it?
One solution is to not make the CATextLayers sublayers of outCircle but for various reasons I need to do it. Thanks for your help in advice!
try setting the inverse-scale value to textLayers.
i.e if you set scale of .5 to shapeLayer, set (1/.5 =2) as scale to textLayers.
shapeLayer.affineTransform =CGAffineTransformMakeScale(.5, .5);
textLayer.affineTransform =CGAffineTransformMakeScale(2, 2);

Performance UIImageView vs UIView with QuartzCore

So I just discovered QuartzCore, and I am now considering to replace a UIImageView containing a bitmap with a UIView subclass doing things like
CGContextFillEllipseInRect(contextRef, rect);
They would look exactly the same: the bitmap is just a little filled circle.
The very view I'm replacing is playing an important role in my app: it's being dragged around a lot.
Question: performance wise: should I bother? I can imagine that the vector circle is being recalculated all of the time, while the bitmap is just buffered. Or that the vector is easier to digest than a bitmap.
Can anyone advise?
thanks ahead
All UIView's on iOS are layer backed. So drawRect will only be called once and you will draw to the CALayer backing the view. You can have it draw again by calling setNeedsDisplay. When you are dragging the view around and drawing it, the view will render from the layer backing. Using a UIImageView is also layer backed and so the end result should be two layer backed views. The one place where you may see a difference is in low memory situations when the view is not visible (though I am not sure).

Round corners in UIView: CALayer or background Image?

I need to make a UIView with rounded corners like this() in tableView with a very large number of items. Therefore, my question is whether the CALayer bad influence on smooth scrolling, and may be better to use for the background image for this case?
Thanks.
CALayer is fine. Transparency is bad for performance though.

Resources