1

I am facing below problem:- Please have a look in the below image the thing what i want is:- enter image description here

I want to drag default images from view 1 to view 2 and images have to be always thr in view1 so its not like touch moved to draging images . i tried a lot things in that but i succeed in draging image from one view to another but in view2 i am not able to get touch points so its just adding thr as frame But i cnt able to touch tht image across view2 and even in view2 i want to do other functionality like zooming and others but first want to get touch points in view2. I am giving description image about this problem.

The edited question is:-

i have done this simple demo in this i am transferring one view to another view and after getting view2 points its been in its limit boundaries. but how can i get the default things remain in their. i will modify this code i will add images in this view. but its just shows my thinking here so guide me here.

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

    UITouch *touch = [touches anyObject];   
    if ([touch view] == view3) {
        CGPoint location = [touch locationInView:self.view];
        view3.center = location;        
        return;
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
        int tmpValue = 0;
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];          
        {
            onceDone = TRUE;
            if(onceDone == TRUE)
            {
                UITouch *touch = [touches anyObject];
                CGPoint pt = [touch locationInView:self.view];
                NSLog(@"X = %f y=%f",pt.x,pt.y);
                view3.center = pt;
                if(view3.frame.origin.x < view2.frame.origin.x )
                   //view3.frame.origin.x < view2.frame.origin.x)
                    [view3 setFrame:CGRectMake(159,view3.frame.origin.y, view3.frame.size.width, view3.frame.size.height)];

            }



        }
    [UIView commitAnimations];
    }

Please help me. it is urgent. Thanks in advance

2
  • if([view3 retainCount]) is complete nonsense.
    – bbum
    Jul 28, 2011 at 15:14
  • It is on comment side.any way i am editing the question Sep 26, 2012 at 12:00

2 Answers 2

3

If you are using pan gestures are touchesMoved method to drag and drop the images.Make super view of view1 and view2 to same UIView and calculate your gesture location or touched point with respect to that common super view.That means your view1 and view2 will be on the same view and each subView(image)is also added to main view only.So you can move images on main view where ever you want and can perform any operation on them.

1
  • Thanks for the reply.I had edited my question and wrote a code below the question.please guide me. Jul 28, 2011 at 6:46
1

We have been working in a similar issue, and we have made up with this solution:

  1. We have an UIPanGestureRecognizer added to each button.

  2. When we detect the pan gesture begin, we create the object we want to drag (in this case, it could be a copy of your image). You should have to set a rect equals to the button, or if you create the object in a different view, you should have to convert the object coordinates so the object seems in the same position as the button, but inside his view.

  3. After that we move the last created object, instead of move the button.

And that is, the trick here is the UIPanGestureRecognizer works until you untouch the screen, but it is triggered while you move your finger for all the screen, not only inside the button!

I hope this works for you.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.