Search code examples
ios6core-animationaqgridview

Custom animations in AQGridView cells happen instantly?


So, I'm working with an AQGridView. We have custom cells with images in them. Now we want the images to bounce when clicked on. I tried operating on the frame of the image, but that didn't work so now I'm trying creating a UIImageView in the main view and giving that a path animation, but what ends up happening is the view just appears in the upper lefthand corder of the cell in question. Here's the relevant code.

-(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)];
}

Solution

  • It was a a threading issue, IIRC. The stuff that happened when a cell was clicked was freezing the 'Pad until the animation was over.