Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone : How do I drag or move UIImage/UIButton as shown below?

I dont know How to get following type of functionality in my app.

enter image description here

As shown in above figure user can slide(drag) different image parts and user can assemble image.

Can any one tell me which control is this ? Or any tutorial for it ?

like image 521
iPhone Avatar asked Dec 05 '11 16:12

iPhone


3 Answers

Check out the MoveMe sample app. It will show you how to allow movement of subviews by touch and drag.

You can then create imageViews for each of your puzzle pieces that can be moved around.

Once you have accomplished this you need to check during movement of a piece to see when it gets close enough to it's correct spot in the puzzle so it can snap into place when then user lets go of the piece.

http://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html

like image 157
jaminguy Avatar answered Nov 05 '22 06:11

jaminguy


That all depends on the kind of implementation you want to do. It can be UIImageView,UIbutton etc. The advantage with UIIMageView could be you can easily implement UIGestureRecognizer to move the views..

like image 45
Abhinandan Sahgal Avatar answered Nov 05 '22 06:11

Abhinandan Sahgal


For an app I built I used the touches functions:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event 
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
- (void) touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event 

for dragging UIImageViews around. Then you can use the CGRectContainsRect or CGRectContainsPoint to detect if the puzzle piece is in the right location.

like image 1
zot Avatar answered Nov 05 '22 06:11

zot