iphone - 为 UITableViewCell 的飞行设置动画

标签 iphone ios

当一个 tableview 单元格被触摸时,我希望单元格的文本飞到一个新的位置。但这似乎不起作用。请指教这里出了什么问题。

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

最佳答案

好吧,这就是我解决它的方法。

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

}

关于iphone - 为 UITableViewCell 的飞行设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18818576/

相关文章:

ios - writeToFile 在 iOS 7 上工作而不在 iOS 6 上工作

iphone - UITableView 无法一直滚动到底部

ios - 如何在 iOS 中将图像转换为视频时为图像制作动画?

ios - UITabBar 的 TabBarItems

ios - Safari IOS 中的 HTML5 视频尺寸

ios - UITableView,如何以编程方式更改整个表格 View 的宽度和高度?

iphone - UITableView 上有多个图像

jquery - 首次访问页面后,CSS 高度转换不适用于 iphone

ios - 无法从视频网址生成缩略图

ios - UICollectionView.dequeueReusableCell 崩溃