gpt4 book ai didi

ios - 动画后 UITableViewCell 位置关闭

转载 作者:行者123 更新时间:2023-11-28 22:02:28 25 4
gpt4 key购买 nike

我在 -(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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com