I am making my first application, which is very similar to solitaire - the user must move the cards and stack them on top of each other. Now I am very new to Objective-C, so I hope you forgive me when my question is stupid.
So, I'm trying to figure it out, and I have two UIImageViews with a UIPanGestureRecgonizer attached to them. Therefore, whenever a user drags one of the cards, he must be on top of the other card. I use the code below in the ViewController.m file, but the problem is that when I drag one card and then want to drag another card, the first card returns to its original position, but I would like it to stay there I dragged it. When I comment on the bringSubviewToFront command, this does not happen, but one of the cards always remains after the other.
-(IBAction)dragCard:(UIPanGestureRecognizer *)recognizer { UIView *cardView = [(UIPanGestureRecognizer *)recognizer view]; [self.view bringSubviewToFront:cardView]; CGPoint translation = [recognizer translationInView:self.view]; recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointZero inView:self.view];}
I can not understand what causes this. Could you help me...
Edit: I registered self.view.subviews to show what is happening. I dragged the image using tag 1, and now I start to drag the image with tag 2. You can see that both coordinates change - the image with tag 1 is returned to its original position, and the image with tag 2 also moves:
2013-05-16 17:02:20.424 ( "<UIImageView: 0x71749e0; frame = (0 0; 320 411); autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7174a40>>", "<UIImageView: 0x7172ef0; frame = (25 77; 42 58); autoresize = TM+BM; tag = 1; gestureRecognizers = <NSArray: 0x7171700>; layer = <CALayer: 0x7171620>>", "<UIImageView: 0x71722f0; frame = (88 200; 42 58); autoresize = TM+BM; tag = 2; gestureRecognizers = <NSArray: 0x7171bc0>; layer = <CALayer: 0x7172350>>" 2013-05-16 17:02:20.441 ( "<UIImageView: 0x71749e0; frame = (0 0; 320 411); autoresize = TM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7174a40>>", "<UIImageView: 0x7172ef0; frame = (30 177; 42 58); autoresize = TM+BM; tag = 1; gestureRecognizers = <NSArray: 0x7171700>; layer = <CALayer: 0x7171620>>", "<UIImageView: 0x71722f0; frame = (91 201; 42 58); autoresize = TM+BM; tag = 2; gestureRecognizers = <NSArray: 0x7171bc0>; layer = <CALayer: 0x7172350>>"
The first ImageView is my background image.
source share