0

I'm using UISwipeGestureRecognizer to slide my UIView up the screen, but I can't figure out how to set its position so that it stays up at the top of the screen until i swipe it back down. Right now I can swipe it up, but it will fall back down right away. Should I be doing a transform instead of CGRectOffset?

- (IBAction)handleSwipe:(UISwipeGestureRecognizer *)recognizer
{

    if(recognizer.direction == UISwipeGestureRecognizerDirectionUp)
    {

        panedView.frame =CGRectOffset( panedView.frame, 0, -1*self.view.bounds.size.height);
    }
}
Brosef
  • 2,945
  • 6
  • 34
  • 69
  • Are you using auto layout? – matt May 25 '14 at 23:58
  • Yes I am. Should I not be? – Brosef May 25 '14 at 23:59
  • Sure but that's the problem. You cannot change the frame of a view controlled by auto layout. Auto layout sets the frame. That is what auto layout is. – matt May 26 '14 at 00:01
  • I just tested it with auto layout turned off and I'm still encountering the same issue – Brosef May 26 '14 at 00:04
  • Nothing wrong with the code you showed. Other code, or auto layout, is moving the view back. – matt May 26 '14 at 00:05
  • I can hold the view in place, if I hold the gesture. But as soon as the gesture ends, the view falls back down. – Brosef May 26 '14 at 00:06
  • You're right. I have a `UIPanGestureRecognizer` on the same view. When its disabled, the view stays where I want it. Any idea how to resolve this? – Brosef May 26 '14 at 00:09
  • You must mediate between them. In all probability, the pan gesture recognizer must require the swipe gesture recognizer to fail ("fail" means "you go first"). You can do this directly or (better) use the UIGestureRecognizerDelegate methods. – matt May 26 '14 at 00:39
  • I tried both `-(BOOL) gestureRecognizer:(UIPanGestureRecognizer*) panGesture shouldRequireFailureOfGestureRecognizer: (UISwipeGestureRecognizer*) swipeGesture` AND `-(BOOL)gestureRecognizer:(UIPanGestureRecognizer *)panGesture shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)swipeGesture`. I guess this is going to require a lot of trial and error to figure out – Brosef May 26 '14 at 01:04
  • It should work if you're doing it right. (Remember that there are LOT of other gesture recognizer that are going to be sent to those methods!) Or follow the direct method, as suggested here: http://stackoverflow.com/a/21728621/341994 However, as that answer points out, you've done a difficult thing, in that pan and swipe are almost the same, so you're introducing a delay into the pan that you might not like. – matt May 26 '14 at 01:40

0 Answers0