【问题标题】:how to rotate image in expandable cell when clicked on cell in ios?单击ios中的单元格时如何旋转可扩展单元格中的图像?
【发布时间】:2016-01-21 06:34:40
【问题描述】:

我正在为 iOS 应用制作一个带有可展开/可折叠单元格的 UITableView。在那个应用程序中,我想显示一个向下箭头的图像,当点击它时,图像将是一个向上箭头。这可能吗?

这是我的代码

-(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];
}

这是我的名为“rotateImage”的图像。请帮我。 这是我的可展开单元格默认图片:

当用户点击一个单元格时,图像将是一个向上的箭头,如果用户再次点击单元格,默认图像应该会再次显示。

【问题讨论】:

  • 请说明您遇到的困难
  • 查看更新问题。谢谢:)

标签: ios uitableview expandable-table


【解决方案1】:

如果您将 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;
}

【讨论】:

  • @MangiReddy,您可以将其标记为正确答案.. ;) 很高兴为您提供帮助。干杯!
  • @MangiReddy,实际上你没有,这是复选标记,但不要担心,重要的是它现在正在工作.. ;)
猜你喜欢
  • 1970-01-01
  • 2015-12-11
  • 1970-01-01
  • 2013-12-05
  • 1970-01-01
  • 2012-06-26
  • 1970-01-01
  • 2017-12-05
  • 1970-01-01
相关资源
最近更新 更多