Rotate UIImageView of UITableViewCell using UIViewAnimation (My app hangs !!)
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 d开发者_运维知识库idSelectRowAtIndexPath:(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.
The (annoying) default with block animations is to disable user interaction. Try this:
[UIView animateWithDuration:10 delay:0
options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAllowUserInteraction
animations:^{
selectedCell.imageView.transform = CGAffineTransformMakeRotation(M_PI);
}
completion:NULL];
精彩评论