문제

I'm trying to replicate the effect done in this gif.

I'm thinking this would be done with UIPanGestureRecognizer, but I'm not sure. Thanks!

도움이 되었습니까?

해결책

This can be accomplished quite easily with UIPanGestureRecognizer. Use translationInView to find out how much the user's finger moved by, and move your view according to the finger movement. In this example, self refers to the view controller, view1 is the view on top you want to drag.

UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];

And handle it:

-(void)handlePan:(UIPanGestureRecognizer*)sender
{
    CGFloat xMovement = [sender translationInView:sender.view].x;
    // Do something with the movement
    view1.frame = CGRectOffset(view1.frame, xMovement, 0);

    // Then reset the translation
    [sender setTranslation:CGPointZero inView:sender.view];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top