[英]Creating a swipe-able app intro screen
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.