[英]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.