简体   繁体   English

创建可滑动的应用介绍屏幕

[英]Creating a swipe-able app intro screen

I'm trying to replicate the effect done in this gif . 我正在尝试复制此gif中完成的效果。

I'm thinking this would be done with UIPanGestureRecognizer, but I'm not sure. 我想这可以通过UIPanGestureRecognizer完成,但我不确定。 Thanks! 谢谢!

This can be accomplished quite easily with UIPanGestureRecognizer. 使用UIPanGestureRecognizer可以很容易地做到这一点。 Use translationInView to find out how much the user's finger moved by, and move your view according to the finger movement. 使用translationInView找出用户的手指移动了多少,并根据手指的移动来移动视图。 In this example, self refers to the view controller, view1 is the view on top you want to drag. 在此示例中,self引用视图控制器,view1是要拖动的顶部视图。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM