ios - Shadows slow up UIScrollView -


i have uiscrollview pretty functions facebook news feed. thought elements slowing scroll fps down. process of elimination, found out shadows slow down app.

the uiview boxes inside scroll view have such configuration:

self.layer.shadowcolor = uicolor.blackcolor().cgcolor self.layer.shadowoffset = cgsizemake(0, 2) self.layer.shadowradius = 2 self.layer.shadowopacity = 0.15 

like news feed, scroll view has many boxes, therefore having uiviews own shadows. how go without slowing down app?

there's bunch of stuff on speeding uiscrollviews:

if use custom calayer instances -- shadows -- stuff requires processing power, should use

scrollview.layer.shouldrasterize = yes; scrollview.layer.rasterizationscale = [uiscreen mainscreen].scale; 

also shadowpath speed scrollview this:

[scrollview.layer setshadowpath:[[uibezierpath bezierpathwithrect:myview.bounds] cgpath]]; 

setting shadowpath allows ios not recalculate how should draw shadow every time draws view, improving performance.

in swift, this:

let shadowpath = uibezierpath(rect: view.bounds); view.layer.maskstobounds = false; view.layer.shadowcolor = uicolor.blackcolor().cgcolor; view.layer.shadowoffset = cgsizemake(0, 0.5); view.layer.shadowopacity = 0.2; view.layer.shadowpath = shadowpath.cgpath; 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -