使用 UIViewAnimation 旋转 UITableViewCell 的 UIImageView (我的应用程序挂起!!)
我将这个 UITableViewCell
放在表格中,并将左侧 imageView
设置为图像。现在我想要的就是当用户选择单元格(别名行)时连续旋转该图像。我可以将单元格 imageView
设置为旋转动画,但一旦执行此操作,应用程序就会停止响应用户输入。换句话说,应用程序挂起并且图像按其应有的方式旋转。下面是相关的代码片段。
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//...
[NSThread detachNewThreadSelector:@selector(rotateImage) toTarget:self withObject:nil];
//...
}
- (void) rotateImage {
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];
[UIView beginAnimations:@"looping animation" context:nil];
// other animation options here if you'd like, and the duration can be anything, not just 3.
[UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionRepeat animations: ^{
// do your rotation stuff on your image, in this block, for the cell you will be returning.
selectedCell.imageView.transform = CGAffineTransformMakeRotation(kDegreesToRadians(90));
} completion:nil];
[UIView commitAnimations];
}
如果我注释 NSThread
代码行,应用程序不会挂起,所以基本上我在动画代码中做错了什么,只是导致应用程序进入挂起状态。
I have this UITableViewCell
in a table with left imageView
set to an image. Now all I want is continuously rotate this image when user selects the cell (alias row). I'm able to animate the cell imageView
to rotate but application stops responding to user inputs once I does so. In other words application hangs and the image rotating as it should be. Below is the relevant code snippet.
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//...
[NSThread detachNewThreadSelector:@selector(rotateImage) toTarget:self withObject:nil];
//...
}
- (void) rotateImage {
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];
[UIView beginAnimations:@"looping animation" context:nil];
// other animation options here if you'd like, and the duration can be anything, not just 3.
[UIView animateWithDuration:10 delay:0 options:UIViewAnimationOptionRepeat animations: ^{
// do your rotation stuff on your image, in this block, for the cell you will be returning.
selectedCell.imageView.transform = CGAffineTransformMakeRotation(kDegreesToRadians(90));
} completion:nil];
[UIView commitAnimations];
}
If I comment the NSThread
code line, application doesn't hang so basically I did something wrong in the animation code only that made the app go in hang state.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
块动画的(烦人的)默认设置是禁用用户交互。试试这个:
The (annoying) default with block animations is to disable user interaction. Try this: