ios - UIView transform inside a UITableViewCell does not work -
i have arrow button inside uitableviewcell should rotate 180 degrees when clicked or when method gets called somewhere else. works when click button , update sender.transform.
@ibaction func rotate(sender: uibutton) { if (top) { uiview.animatewithduration(0.5, animations: { sender.transform = cgaffinetransformmakerotation((360.0 * cgfloat(m_pi)) / 180.0) }) } else { uiview.animatewithduration(0.5, animations: { sender.transform = cgaffinetransformmakerotation((180.0 * cgfloat(m_pi)) / 180.0) }) }
}
if change code reference button instead uitableviewcell this, not work. button not rotate.
ibaction func rotate(sender: uibutton) { let detailcell = tableview.cellforrowatindexpath(nsindexpath(forrow: 0, insection: 0)) as! detailcell if (top) { uiview.animatewithduration(0.5, animations: { detailcell.arrowbutton.transform = cgaffinetransformmakerotation((360.0 * cgfloat(m_pi)) / 180.0) }) } else { uiview.animatewithduration(0.5, animations: { detailcell.arrowbutton.transform = cgaffinetransformmakerotation((180.0 * cgfloat(m_pi)) / 180.0) }) }
}
basically, want able rotate button uitableviewcell in method not involve clicking button, need able reference button uitableviewcell , rotate it. right way this?
you have couple of different choices.
if create custom subclass of uitableviewcell
can add outlet button cell. ask table view cell, cast to custom class, , use outlet button (mycustomcell.button
).
the other option add unique tag button, , use cell.contentview.viewwithtag(tagnumber)
. cast result uiview uibutton.
using custom subclass of uitableviewcell
, outlet cleaner , less fragile, more work set up.
Comments
Post a Comment