如何在ios中单击单元格时在可扩展单元格中旋转图像?

时间:2016-01-21 06:34:40

标签: ios uitableview expandable-table

我正在为iOS app.in创建一个带有可扩展/可折叠单元格的UITableView,我希望在用户点击单元格图像时显示为Down,再次点击它时图像将像这样显示为Up,它是可能! 这是我的代码

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedIndex == indexPath.row)
{
    selectedIndex = -1;
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    return;
}
if (selectedIndex != -1)
{
    NSIndexPath *prevPath = [NSIndexPath indexPathForRow:selectedIndex inSection:0];
    selectedIndex = indexPath.row;
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prevPath] withRowAnimation:UITableViewRowAnimationFade];
}
    selectedIndex = indexPath.row;
    [myContestTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

在这个我的图像名称是“rotataeImage”请帮助我。 这是我的可扩展单元格默认图像是这样的

enter image description here

当用户点击单元格时,图像将显示为UP,再次用户单击单元格默认图像将显示在此处

1 个答案:

答案 0 :(得分:2)

如果您继续使用UITableViewCell setSelected: animated:继承,可以使用:- (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; YOURIMAGEVIEW.transform = CGAffineTransformMakeRotation(selected ? M_PI : 0); // Configure the view for the selected state } ,在那里添加配置。

-cellForRowAtIndexPath

如果没有,你只需在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... YOURTABLECELL.yourImageView.tranform = CGAffineTransformMakeRotation((selectedIndex == indexPath.row) ? M_PI : 0); ... return tableCell; } 内使用,如:

.main-outer-div-filter {
    max-height: 230px;
}