【发布时间】:2015-06-13 14:50:08
【问题描述】:
我在 UITableViewCell 中有这个向上箭头按钮,当单击或在其他地方调用该方法时,它应该旋转 180 度。当您单击按钮并更新 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)
})
}
}
如果我更改代码以便将按钮从 UITableViewCell 引用到类似的东西,这不起作用。按钮不旋转。
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)
})
}
}
基本上,我希望能够以不涉及单击按钮的另一种方法从 UITableViewCell 旋转按钮,因此我需要能够从 UITableViewCell 引用按钮并旋转它。这样做的正确方法是什么?
【问题讨论】:
标签: ios iphone swift uitableview uiview