ios - UITableViewCell shadow disappears after scroll -
i have subclassed uitableviewcell class add shadow below cell. shadow added correctly, when tableview appears on screen. but, when scroll tableview down, , cell shadow hides above screen, shadow disappears.
- (void)layoutsubviews { [super layoutsubviews]; if (self.shouldaddshadow) { self.layer.shadowopacity = 0.5; self.layer.shadowradius = 1.5; self.layer.shadowoffset = cgsizemake(0, 3); self.layer.shadowcolor = [[[uicolor appdarkdividercolor] colorwithalphacomponent:0.9] cgcolor]; [self setclipstobounds:no]; [self.layer setmaskstobounds:no]; cgrect shadowframe = self.layer.bounds; cgpathref shadowpath = [uibezierpath bezierpathwithrect:shadowframe].cgpath; self.layer.shadowpath = shadowpath; } }
forgot mention, have tableview static cells; prepareforreuse isn't called. have outlets cells, i've tried set shadow cell in scrollviewdidscroll: method. din't me
i encountered problem. find way make work.
it doesn't disappear(removed), been hidden.
there use property zposition
of cell's layer.
from apple docs:
the default value of property 0. changing value of property changes the front-to-back ordering of layers onscreen. can affect visibility of layers frame rectangles overlap.
the value of property measured in points.
the default value 0
. leads top cell hides bottom cell (say shadow). means if set shadow view make show in both sides , margin before 2 cell zero, bottom shadow of top cell show up, top shadow of bottom shadow hidden.
when cell goes out of screen , back, though zposition
of each cell still 0
, cells, bottom cell hides top cell now. hide direction opposite scroll direction. situation met.
so,
cell.layer.zposition = <#value want#>
for example, want show shadow of siblings, can set zposition
of cell's layer -1
, shadow of both side appear.
zposition
of layer decide cell can show in front, , shows in back. z-index
in css.
so solution change zposition property make work expected.
in addition, should not set cell's clipstobounds
yes
. (default value no)
Comments
Post a Comment