Minestrone-Soup
Minestrone-Soup

Reputation: 399

How to get location of moving a UIImageView

In touchesBegan I have this, and some other irrelevant code. :

CGPoint center;
center = [[self.squareOne.layer presentationLayer] center];

squareOne uses a block-based UIView animation to move. The animation code:

self.squareOne.center = position;
self.squareOne.transform = CGAffineTransformMakeRotation((a + 1) * M_1_PI);

If it really matter this is what position is:

position.x = self.widthOfScreen/8 + self.widthOfScreen;
position.y = y;
//y is any number between 0 and the height of the screen

But when I click the screen, I get the dreaded: Thread 1: signal SIGABRT error. (I say the other code in touchesBegan is irrelevant because those 2 lines of code are the problem. Pretty much the rest are just if-statements which will ultimately just make squareOne become hidden). I am asking how I can get the location of a UIImageView mid-animation when I click the screen. It doesn't matter if you get the center, I just want to know how to get a relative value of squareOne's position while it's moving.

Upvotes: 1

Views: 49

Answers (1)

Skyler Lauren
Skyler Lauren

Reputation: 3812

I think the issue is that there is no center on a presentation layer, but you can get a frame. Try this...

 CALayer *layer = self.squareOne.layer;
 CGRect frame = [[layer presentationLayer] frame];
 CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMaxY(frame));

Hopefully that helps.

Upvotes: 1

Related Questions