Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell位置在动画后关闭_Ios_Objective C_Uitableview_Core Animation - Fatal编程技术网

Ios UITableViewCell位置在动画后关闭

Ios UITableViewCell位置在动画后关闭,ios,objective-c,uitableview,core-animation,Ios,Objective C,Uitableview,Core Animation,我在-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)单元格for rowatindexpath:(nsindepath*)中有一个动画。这些单元格基本上是按顺序旋转的(代码如下)。每次加载到屏幕上时都会这样做。最初旋转的单元格(即开始时在屏幕上可见的单元格)看起来像下面的“之前”快照。小(正常)压痕。向下或左右滚动后,屏幕上会显示新单元格的动画,但它们看起来像“之后”快照。它们相差了几个像素。一

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

之前:

之后:

//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];

尝试通过编程设置图层的位置谢谢您的建议!但是,在尝试之后,同样的行为发生了:(只需记录并检查动画前后每个单元格的位置!它为所有单元格前后返回0.000000,包括明显偏移的单元格。这意味着什么?!你的意思是你这样做了
NSLog(@“x->%f,y->%f”,cell.layer.position.x,cell.layer.position.y)
y的位置可能会改变,但x的位置会给出zeroYep!这是完全正确的。我希望看到有问题的单元格的值略有不同,但它也返回了0。这让我想知道问题是否不是单元格的位置,而是它可能有一些填充属性?