如何在ios中的单元格上单击时在可展开单元格中旋转图像?
问题描述:
我正在做一个UITableView与iOS应用程序的可展开/可折叠单元格,我想显示,当用户点击单元格图像将下来,当再次点击它时,图像将是这样的,这是可能的! 这里是我的代码如何在ios中的单元格上单击时在可展开单元格中旋转图像?
-(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”请帮助我。 这里是我膨胀的室默认的图像就像是在细胞这个
当用户点击图像会,并再次对细胞的默认图像用户点击将在这里显示
答
如果你继承你可以使用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;
}
请解释的困难,你面对 –
查看更新的问题。谢谢:) –