uitableview - How can I animate any UIView inside UITableViewCell? -
let label = uilabel(frame: cgrectmake(20.0, 20.0, 15.0, 15.0)) label.backgroundcolor = uicolor.flamingocolor() uiview.animatewithduration(3.0, animations: { cell.addsubview(label) label.backgroundcolor = uicolor.yellowcolor() })
this code put inside tableview:cellforrowatindexpath:
-> result subview has yellow background, haven't seen animation. same method tableview:didenddisplayingcell:
which method should use or kind of animation should put there see animations inside uitableviewcell. know cannot animate existing labels, because these constraints.
firstly, should move cell.addsubview(label)
outside of animation block , add label contentview
of cell.
back problem. can't animate background colour of uilabel. use uiview, of same size, behind uilabel same effect though.
to uiview change colour once it's appeared used uitableviewcell subclass:
class animatedcell : uitableviewcell { let animatedview = uiview() /* setup adding animatedview contentview , setting animated view's initial frame , colour. */ func animate() { uiview.animatewithduration(3.0) { animatedview.backgroundcolor = uicolor.redcolor() } }
then in uitableviewcontroller
subclass, when view controller presented uitableview
populated need animate cells with:
override func viewdidappear(animated: bool) { super.viewdidappear(animated: bool) cell in tableview.visiblecells() as! [uitableviewcell] { if let animatedcell = cell as? animatedcell { animatedcell.animate() } } }
then, cells appear when scroll:
override func tableview(tableview: uitableview, willdisplaycell cell: uitableviewcell, forrowatindexpath indexpath: nsindexpath) { if let animatedcell = cell as? animatedcell { a.animatelabel() } }
also, can animate autolayout, need change constant
on nslayoutconstraint
want animate. gives example: ios: how 1 animate new autolayout constraint (height)
Comments
Post a Comment