ios - 动画后 UITableViewCell 位置关闭

标签 ios objective-c uitableview core-animation

我在 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *) 中进行动画。细胞基本上旋转(下面的代码)。他们每次加载到屏幕上时都会这样做。最初旋转的单元格(即开始时在屏幕上可见的单元格)看起来像下面的“之前”快照。小(正常)压痕。向下或左右滚动后,新的单元格会动画显示在屏幕上,但它们看起来像“After”镜头。它们相差几个像素。一旦我再次向上滚动,上面的单元格就会重新加载,并且缩进也更大。所有这些都很好,除了取决于滚动行为,有时一些单元格是缩进的,而另一些不是,它看起来很糟糕。我尝试重置 UITableViewCell 的缩进属性,但它没有做任何事情。有什么想法会导致这种奇怪的行为吗?也许我不知道我应该设置的属性?谢谢!

之前:

enter image description here

之后:

enter image description here

//Animation Code Borrowed From http://www.thinkandbuild.it/animating-uitableview-cells/
//1. Setup the CATransform3D structure
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;

//2. Define the initial state (Before the animation)
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;

cell.layer.transform = rotation;
cell.layer.anchorPoint = CGPointMake(0, 0.5);

//3. Define the final state (After the animation) and commit the animation
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];

编辑 再次访问原始站点的源代码后,我注意到代码有更新并应用了它:

if(cell.layer.position.x != 0){
    cell.layer.position = CGPointMake(0, cell.layer.position.y);
}

但是,它似乎并没有解决这个问题,我认为这是解决这个动画存在的另一个定位问题。

最佳答案

我不确定,试一试,

只需将图层位置强制为原点,请参见下面的代码

//1. Setup the CATransform3D structure
CATransform3D rotation;
rotation = CATransform3DMakeRotation( (90.0*M_PI)/180, 0.0, 0.7, 0.4);
rotation.m34 = 1.0/ -600;


//2. Define the initial state (Before the animation)
cell.layer.shadowColor = [[UIColor blackColor]CGColor];
cell.layer.shadowOffset = CGSizeMake(10, 10);
cell.alpha = 0;

cell.layer.transform = rotation;
cell.layer.anchorPoint = CGPointMake(0, 0.5);

if(cell.layer.position.x != 0)
{
    cell.layer.position = CGPointMake(0, cell.layer.position.y);
}

//add this and try
CGPoint point = cell.layer.position;
point.x = 0.0f; //setting the position back to original (for your case)
cell.layer.position = point;


//4. Define the final state (After the animation) and commit the animation
[UIView beginAnimations:@"rotation" context:NULL];
[UIView setAnimationDuration:0.8];
cell.layer.transform = CATransform3DIdentity;
cell.alpha = 1;
cell.layer.shadowOffset = CGSizeMake(0, 0);
[UIView commitAnimations];

关于ios - 动画后 UITableViewCell 位置关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24817285/

相关文章:

ios - Objective-C:如何让AVPlayer在后台继续播放

iphone - 显示 UILabel * 秒;除了 NSTimer 之外还有其他方法吗?

objective-c - 如何生成动态属性getter/setter?

ios - 如何从这个json中获取数据

ios - 是否可以为 MGLPolyline 创建自定义弹出窗口?

objective-c - 如何在表格 View 的单元格中创建按钮?

ios - Quickblox - 获取用户 friend 的头像并显示在 UITableView 中

ios - 我可以在 Storyboard 中设置分组的 tableView 节号吗?

ios - 无法删除 TableView 中的某些行

ios - -productRequest :didReceiveResponse returns empty products array in real store, 在沙盒中工作