6

I am Developing a game in which a UIImageView moves along a Bezier path. I want to provide user interaction to the moving UIimageview so that the user can guide the UIImageView by touching the UIImageView, and dragging it around the path! How does one do that?

enter image description here

Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32
Manjit Singh
  • 238
  • 2
  • 10

3 Answers3

0

Simply use pan gesture and add it to UIImageView and provide your path along which user move it.Pan Gesture

This link might be helpful in understanding and implementing same. Anything else let me know.

nikhil84
  • 3,235
  • 4
  • 22
  • 43
  • i want to provide user interaction to the moving UIimageview so that user can guide the UIImageView by touching the UIImageview and drag the UIImageview around a Bezier path. – Manjit Singh Jun 23 '14 at 12:33
  • So I have provided you with link ,just go through it and see if it work's fine for you. Hope this does else let me know I would find in something else for you – nikhil84 Jun 23 '14 at 12:35
  • For that bezier path you should provide it as a big line/rope to user so he/she could know along which path he/she has to move that image. – nikhil84 Jun 23 '14 at 12:37
  • Rest I don't have much idea about your game and plot of it. – nikhil84 Jun 23 '14 at 12:37
  • i see that link that link is just to move the image around screen i want when user touch the image the image drag and flow a path that is predefined. – Manjit Singh Jun 23 '14 at 12:40
  • So when pan gesture is detected and function is called then you could check for path and do as per your logic that is to move image or not. – nikhil84 Jun 23 '14 at 12:42
  • Also could you provide some idea abut your game ? – nikhil84 Jun 23 '14 at 12:42
  • Check this [Documentation](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/Timing.html#//apple_ref/doc/uid/TP40006670-SW1) and [link](http://stackoverflow.com/questions/1142727/how-can-i-animate-the-movement-of-a-view-or-image-along-a-curved-path) – nikhil84 Jun 23 '14 at 12:44
  • see i add a image i want the user touch the image and image move along the the D letter with user touch not with animations – Manjit Singh Jun 23 '14 at 12:50
  • Do check out link which I provided above(recent one). Also u want image to move along D letter path(like in D shape) ?? – nikhil84 Jun 23 '14 at 12:54
  • i already move the image using the animation but i want it that user touch the image when user drag the image the image follow the path and move along the user touch but in the path .if user move outside the path the image does not move – Manjit Singh Jun 23 '14 at 12:58
  • Use this -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event and in dis before placing your image just check it's point with bezier path point's if match den place image else move it to previous point's. – nikhil84 Jun 23 '14 at 12:59
  • So whenever point match's den put that point in previous and check for next point's of image. – nikhil84 Jun 23 '14 at 13:01
  • As you draw a bezier path so must be having that points and just cross check it. Also me looking for a alternative for it. So if I come across any then would let u know – nikhil84 Jun 24 '14 at 04:01
  • we draw bezier using lines like add line from start to end point – Manjit Singh Jun 24 '14 at 05:53
  • So you do get the start and end point's then you need to store all points and keep a check for moving of imageView. – nikhil84 Jun 24 '14 at 06:25
  • that i dont know to store the points from the bezier path if you have any code or any example please send me – Manjit Singh Jun 24 '14 at 06:37
  • I don't have example and I'm stuck with other stuff. I find out this [link](http://stackoverflow.com/questions/4058979/find-a-point-a-given-distance-along-a-simple-cubic-bezier-curve-on-an-iphone) might help you out ! hope so... – nikhil84 Jun 24 '14 at 06:41
  • Upload your code on github and share the link. Will look into that one where your animating the imageView and try to get in changes you require. – nikhil84 Jun 24 '14 at 06:44
0

You have to check whether the touch point coordinates are inside Beizer Path. If it is inside allow UITouch and Movement, else not. Give If Condition accordingly.

Vipin Vijay
  • 393
  • 5
  • 21
0

Please try this...

Here selectedImageCat is gobal uiimageview object and touchimgView is select(touched) imageview

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        for (UITouch *touchPoint in touches)
        {
              if(CGRectContainsPoint(touchimgView.frame, [touchPoint locationInView:self.view]))
        selectedImageCat=(UIImageView*)touchimgView;

        }
    }

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        if (selectedImageCat!=nil)
        {
            CGPoint pt = [[touches anyObject] locationInView:self.view];
            [selectedImageCat setCenter:pt];
        }
    }

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


        //here you provide final frame for touchimgView object
    }
Rohit
  • 577
  • 1
  • 3
  • 13