質問

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