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

Grannyville7989

macrumors 6502a
Original poster
Aug 2, 2010
549
0
I'm new to iOS programming and I'm trying to get a particular task done but I'm having difficulty finding the information for what I'm looking for so I thought I'll give it a shot here.

I've got a view with four UIImageViews in a row at the top screen, which can be dragged around with your finger. I want to know how I can make it so that once an image has been dragged into a particular area on screen, it will "snap" into that area. And if the image is not dragged into that particular area on the screen, it springs back to it's original starting point, with an animation of it springing back there.

I can providing more information on request if needed.
 
Take a look at the animation methods in the UIView documentation. You could also try a google search like "Animating UIView" and you might find some decent examples.

In short you can nearly automatically animate the movement of a view when you change the view's frame.
 
Use Animation blocks, by setting the frame/center of it, and it should take care of the smoothness on OS Level.
And the check of being in that area is checking something like
CGRectIntersects (or something, top of my head).
on the drag function.

Greetz, Noxx
 
Take a look at the animation methods in the UIView documentation. You could also try a google search like "Animating UIView" and you might find some decent examples.

In short you can nearly automatically animate the movement of a view when you change the view's frame.

Thank you. I exactly sure what I should punch into Google to look up what I wanted. I'll give it a gander later on today.
 
I'm new to iOS programming and I'm trying to get a particular task done but I'm having difficulty finding the information for what I'm looking for so I thought I'll give it a shot here.

I've got a view with four UIImageViews in a row at the top screen, which can be dragged around with your finger. I want to know how I can make it so that once an image has been dragged into a particular area on screen, it will "snap" into that area. And if the image is not dragged into that particular area on the screen, it springs back to it's original starting point, with an animation of it springing back there.

I can providing more information on request if needed.

UIImageView doesn't snap positions, that's something you have to do in code.

I would just check the distance between the empty slot and the image, and if it's within
a specific range, animate it to the slot. Otherwise animate it back to its original position.

Basic animation:
Code:
[UIView beginAnimations: nil context: NULL];
myImageView.frame = CGRectMake(50,50, 100,100);			// move to here
[UIView commitAnimations];

You can set additional options, such as delegate, duration, curve parameters, etc... if needed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.