Reputation: 1579
When a tableview cell is touched, I want the text of the cell to fly to a new location. But this doesn't seem to work. Please advice what is going wrong here.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView1 deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CGRect cellRect = [cell.superview convertRect:cell.frame toView:self.view];
// The cell should be shown in table as well, so create a new cell
UITableViewCell *view1 = [[UITableViewCell alloc] initWithFrame:cellRect];
[self.view addSubview:view1];
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationCurveEaseOut
animations:^{
view1.frame = CGRectMake(10, 10, 0, 0);
}
completion:^(BOOL finished){
NSLog(@"Done!");
[view1 removeFromSuperview];
[self songAddedToQ:indexPath];
}];
}
Upvotes: 0
Views: 385
Reputation: 1579
Ok this is how I solved it.
-(UIImage*) returnCellImage:(UITableViewCell*)cell
{
UIGraphicsBeginImageContext(cell.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[cell.layer renderInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return screenShot;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView1 deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIImage *image = [self returnCellImage:cell];
CGRect cellRect = [cell.superview convertRect:cell.frame toView:self.view];
UIImageView *view1 = [[UIImageView alloc] initWithFrame:cellRect];
[view1 setImage:image];
[self.view addSubview:view1];
[UIView animateWithDuration:0.5
delay:0
options: UIViewAnimationCurveEaseOut
animations:^{
view1.frame = CGRectMake(10,10, 0, 0);
}
completion:^(BOOL finished){
[view1 removeFromSuperview];
}];
}
Upvotes: 1