Reputation: 424
I think the title is pretty self explaining. I need an icon that is dragged by users touch. If this icon is droped on a certain area I would like to call a function. How´s that possible?
Thanks a lot,
Tyler
Upvotes: 0
Views: 111
Reputation: 954
- (void)viewDidLoad { [super viewDidLoad]; UIPanGestureRecognizer *pangesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(imageIsMoved:)]; pangesture.minimumNumberOfTouches = 1; [self.myView addGestureRecognizer:pangesture]; }
-(void)imageIsMoved:(UIPanGestureRecognizer *)gesture{ CGRect frameToBeCompared; if (gesture.state == UIGestureRecognizerStateEnded) { UIView *v = [gesture view]; CGRect viewFrame = v.frame; if (CGRectEqualToRect(frameToBeCompared, viewFrame)) { [self callMyMethod]; } } }
Upvotes: 1
Reputation: 687
Check out this thread. Once you have the basics down, you can use an if statement to check the bounds of your icon and if they hit a specific spot call your next function.
Here's another example from one of my favorite iOS tutorial sites, www.raywenderlich.com
Upvotes: 0