例如,在iOS 7/8锁定屏幕上,如果点击而不是将其拖动到右侧,则会产生轻微的反弹效果。如何检测轻击手势(并且不要将其与拖动相混淆)并重新创建类似微妙的“反弹”效果?任何人都可以共享代码示例(swift / obj-c)吗?
我认为这是一种很好的方式来向用户显示应该拖动某些东西而不是点击它,并且不需要读取任何小指示符。
答案 0 :(得分:2)
将tap gesture
添加到您的视图中:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];
可以使用UIView's
方法
animateWithDuration
handleTap:
方法完成
- (void)handleTap:(UITapGestureRecognizer*)gesture
{
__block CGRect frame = scrollView.frame;
[UIView animateWithDuration:0.3 delay:0.0 options: UIViewAnimationOptionCurveLinear
animations:^{
frame.origin.x += 20.0f;
scrollView.frame = frame;
}
completion:^(BOOL finished){
scrollView.frame = frame;
}];
}
答案 1 :(得分:1)
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recognizeYourTap:)];
[self.yourView addGestureRecognizer:gestureRecognizer];
gestureRecognizer.cancelsTouchesInView = NO;
- (void) recognizeYourTap:(UITapGestureRecognizer*)ges
{
//DO your Animation stuff what prince mentioned
}
答案 2 :(得分:1)
您可以在视图上使用UITapGestureRecognize
映射点按手势。但是你必须实现一些UIGestureRecognizerDelegate
方法来处理两个手势识别器。
使用UIView
animateWithDuration或使用CoreAnimation
框架