所以,我正在使用 AQGridView。我们有自定义单元格,其中包含图像。现在我们希望图像在点击时反弹。我尝试对图像的框架进行操作,但这不起作用所以现在我尝试在主视图中创建一个 UIImageView 并为其提供路径动画,但最终发生的是视图只出现在左上角有问题的细胞的绳索。这是相关的代码。
-(void)bounce:(CoverGridCell*)v {
UIView * w = [v.subviews objectAtIndex:0];
UIImageView * u = [[UIImageView alloc] initWithImage:v.image];
u.frame = [self.view convertRect:[[w.subviews objectAtIndex:0] frame] fromView:w];
double __block y = u.frame.origin.y;
double __block x = u.frame.origin.x;
[self.view addSubview:u];
CGMutablePathRef cgmp = CGPathCreateMutable();for (int j= 10; j > 0;j--) {
CGAffineTransform t1 = CGAffineTransformMakeTranslation(0, - j*j);
CGAffineTransform t2 = CGAffineTransformInvert(t1);
CGPathMoveToPoint(cgmp,&t1, x, y - j * j);
CGPathMoveToPoint(cgmp,&t2, x, y);
}
CGPathRef cgp = CGPathCreateCopy(cgmp);
CGPathRelease(cgmp);
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath: @"position"];
anim.duration = 5.0;
anim.delegate = self;
anim.path = cgp;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
[u.layer addAnimation:anim forKey:@"DoesThisMatter"];
[u.layer setPosition:CGPointMake(x,y)];
}