Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
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.
 
Last edited:
I set a breakpoint in Xcode, and it looks like differencePoint.x is always positive.
 
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.