I’ve created a document view which displays the page number in the corner. The page number is a uilabel with a semi-transparent background colour, and has a corner radius (using the cornerRadius property of the view‘s layer). I’ve positioned this above a UIScrollView. However, this makes scrolling jerky. If I remove the cornerRadius, performance is good. Is there anything I can do about this? What would be a better solution? It seems to have been achieved in the UIWebView without any performance issues.
I’ve created a document view which displays the page number in the corner. The
Share
For labels, or views with rounded corners and or background colors and shadows on scrolling views the solution is pretty simple:
The biggest issue is from the masksToBounds layer option. This appears to tax performance significantly, however the label seems to need this ON to mask the background color to rounded corners. So to get around this you need to set the labels layer background color instead and switch off masksToBounds.
The second issue is that the default behavior is to redraw the view whenever possible which is totally unnecessary with static or slow changing items on scrolling views. Here we simply set layer.shouldRasterize = YES. This will allow CA to ‘cache’ a rasterized version of the view for quick drawing when scrolling (presumably with hardware acceleration).
You need to make sure your layer has an alpha channel otherwise rasterizing will affect the drawing of rounded corners. I’ve never had a problem as I have alpha set for my background colors, but you may need to check in your situation.
Here is a sample UILabel set up to work nicely on a scollview:
I can fill the iPad 1 screen with views like this and still scroll smoothly 🙂