[英]Creating a swipe-able app intro screen
使用UIPanGestureRecognizer可以很容易地做到这一点。 使用translationInView找出用户的手指移动了多少,并根据手指的移动来移动视图。 在此示例中,self引用视图控制器,view1是要拖动的顶部视图。
UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
并处理:
-(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.