I have an ViewController class, where i have an UIView called templateView
on self.view, which consists of an UIView called gridView
, here i need to swipe on templateView
, for that i have added swipegesture like,
swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction)];
swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[templateView addGestureRecognizer:swipeRight];
[templateView addGestureRecognizer:swipeLeft];
In the swipeRight
and swipeLeft
i need to move the gridView
left side and right side.. What i need to implement in these methods..?
You can move the gridView by using some UIViewAnimations. Create something like that:
This code will change the frame of your gridView. You need to change this parameter according to where you want to slide your view. I didn't try the code, let me know if it works.
I'd suggest
Use a gesture handler that takes a parameter (in case you ever add gestures to multiple views);
Make sure the view in question has
userInteractionEnabled
turned on.You don't need to set the gesture's
delegate
unless you're implementing one of theUIGestureRecognizerDelegate
methods.Thus, the configuration might look like:
And then the gesture handler might look like:
Note, if you're using auto layout and if the view is defined by constraints rather than
translatesAutoresizingMaskIntoConstraints
, then this handler code would have to change appropriately. But hopefully this gives you the basic idea.