ios - 添加新的UITableViewRow会使现有单元格下降得太快

标签 ios objective-c uitableview uiviewanimation

我正在尝试创建UITableCellView动画,例如Peek Calendar。如此处所示:

我正在使用UITableView和以下代码进行动画处理

//Animaiton for the table view cells to appear
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if([cell.reuseIdentifier isEqualToString:@"HolidayCell"]) {

        int x = (indexPath.row-self.selectedMonth) %2;
        //1. Setup the CATransform3D structure
        CATransform3D rotation;
        CATransform3D position;

        position = CATransform3DMakeTranslation(0, -36, 0) ;

        //rotation.m33 = 12;
        UILabel *shadow = (UILabel*)[cell.contentView viewWithTag:2];

        //2. Define the initial state (Before the animation)
        cell.alpha = 1;
        shadow.alpha = 0.75;

        if(x==1) {
            rotation = CATransform3DMakeRotation((-90.0*M_PI)/180, 1.5, 0.0, 0.0);
            rotation.m34 = 0.0059;
            cell.layer.anchorPoint = CGPointMake(0.5, 0.0);    
        }
        else
        {
            rotation = CATransform3DMakeRotation((90.0*M_PI)/180, 1.5, 0.0, 0.0);
            rotation.m34 = 0.0059;
            cell.layer.anchorPoint = CGPointMake(0.5, 1.0);
        }

        cell.layer.transform = CATransform3DConcat(position, rotation);

        //3. Define the final state (After the animation) and commit the animation
        [UIView beginAnimations:@"rotation" context:NULL];
        [UIView setAnimationDuration:2.3];
        //[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell cache:YES];
        cell.layer.transform = CATransform3DIdentity;
        cell.alpha = 1;
        shadow.alpha = 0;
        //cell.layer.shadowOff

 1. List item

set = CGSizeMake(0, 0);
        [UIView commitAnimations];
    }
}

现在,我对动画没有任何问题。细胞旋转得很好。但是我的问题是,即使旋转时我插入一个单元,它仍然会占据空间,就好像它完全打开一样。

如您所见,这些单元在它们的“虚拟盒子”内旋转,但是我希望这些单元像下面的图像那样粘在一起:

有人对如何执行此操作有任何想法吗?

最佳答案

您不变换帧,仅变换图层。该层仅是单元的视觉表示,并不定义单元的大小或位置。

我相信,在tableView中,单元格的框架首先由heightForRowAtIndexPath:方法定义,但是稍后应该可以使用“frame”属性对其进行更改和设置动画。尝试将其设置为零,并在单元格出现时动画化为最终高度。

代码,最终给出了解决方案:https://www.cocoacontrols.com/controls/jtgesturebasedtableviewdemo

关于ios - 添加新的UITableViewRow会使现有单元格下降得太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21999126/

相关文章:

ios - UITableview 部分索引点击事件

ios - 如何切换 View 和释放先前 View 的内存

ios - uitableview cell cellForRowAtindexPath 从 swift3 中的名称中获取第一个字母

objective-c - Xcode & 网页 View : Load local html if no internet connection (fallback)

swift - TableViewCell 导致具有不同细节的单一 View Controller SWIFT

ios - 如何在 UITableView 框架中获取手势识别器的位置,而不是边界

iphone - 使用 locationOfTouch 查找手势触摸的坐标

ios - iOS 中 @available 命令的 Travis 错误

iphone - MFMessageComposeViewController:如何限制以蜂窝消息而不是 iMessage 的形式发送消息

objective-c - 在 cocoa 中读取、修改、写入xml文件