Resolved Burst effect not happening

Discussion in 'iOS Programming' started by moonman239, Aug 12, 2014.

  1. moonman239, Aug 12, 2014
    Last edited: Aug 13, 2014

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I have a set of animated image views that are supposed to start out clustered around a bigger image view that contains an image of a balloon, then spread out. To the user, it's supposed to look like that balloon has bursted into pieces.

    Here's the code:
    Code:
    CGPoint differencePoint = [[self view] convertPoint:[BalloonPieceImageView center] toView:[self stillBalloonImageView]];
            CGFloat angle = atan2f(differencePoint.y, differencePoint.x);
            CGFloat destinationX = cosf(angle) * radius;
            CGFloat destinationY = sinf(angle) * radius;
            if (differencePoint.x < 0) {
                destinationX = -destinationX;
            }
            CGPoint destination = [[self view] convertPoint:CGPointMake(destinationX, destinationY) fromView:[self stillBalloonImageView]];
            [UIView animateWithDuration:2 animations:^{ [BalloonPieceImageView setCenter:destination]; }];
    
    However, for some reason, some of the image views are not going the right way. Edit: I don't think the problem lies with the coordinates of any of the image view centers.
     
  2. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #2
    I set a breakpoint in Xcode, and it looks like differencePoint.x is always positive.
     
  3. moonman239, Aug 13, 2014
    Last edited: Aug 13, 2014

    moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    It looks like the reason I couldn't get the burst effect to work properly is that differencePoint's coordinates were relative to the bottom-left corner of the unanimated image view, not the image view's center.

    Edit: I also removed the if block, including everything in it, because it did not help. atan2f will return a negative angle if either x or y is negative, and cosf will return a negative value if the given angle is negative.
     

Share This Page