【问题标题】:Rotate UIImageView of UITableViewCell using UIViewAnimation (My app hangs !!)使用 UIViewAnimation 旋转 UITableViewCell 的 UIImageView(我的应用挂起!!)
【发布时间】:2011-08-31 22:01:51
【问题描述】:

我在一个表中有这个 UITableViewCell,左 imageView 设置为一个图像。现在我想要的只是当用户选择单元格(别名行)时不断旋转这个图像。我可以为单元格 imageView 设置动画以进行旋转,但一旦我这样做,应用程序就会停止响应用户输入。换句话说,应用程序挂起,图像按原样旋转。下面是相关代码sn-p..

  • (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { ... [NSThread detachNewThreadSelector:@selector(rotateImage) toTarget:self withObject:nil];

.... }

  • (void) 旋转图像 { UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];

    [UIView beginAnimations:@"循环动画" context:nil]; // 如果你愿意,这里还有其他动画选项,持续时间可以是任何东西,而不仅仅是 3。

    [UIView animateWithDuration:10 延迟:0 选项:UIViewAnimationOptionRepeat 动画:^{ // 在你的图像上做你的旋转,在这个块中,为你将要返回的单元格。 selectedCell.imageView.transform = CGAffineTransformMakeRotation(kDegreesToRadians(90)); } 完成:无];

    [UIView 提交动画];
    }

如果我注释 NSThread 代码行,应用程序不会挂起,所以基本上我在动画代码中做错了什么,只是让应用程序进入挂起状态。

请帮忙!! TIA

【问题讨论】:

    标签: uitableview uiimageview rotation freeze uiviewanimation


    【解决方案1】:

    块动画的(烦人的)默认设置是禁用用户交互。试试这个:

    [UIView animateWithDuration:10 delay:0
                        options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                        selectedCell.imageView.transform = CGAffineTransformMakeRotation(M_PI);
                    }
                     completion:NULL];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      相关资源
      最近更新 更多