例如在iOS 7/8的锁屏上,如果点击而不是向右拖动,会有轻微的弹跳效果。我如何检测点击手势(而不是将其与拖动混淆)并重新创建类似的微妙“弹跳”效果?谁能分享一个代码示例 (swift/obj-c)?
我认为这是向用户表明应该拖动而不是点击某些内容的好方法,并且不需要阅读任何小指示器。
最佳答案
像这样将点击手势
添加到您的 View 中:
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];
可以在handleTap:
方法中使用UIView 的
animateWithDuration
方法
- (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;
}];
}
关于ios - 如何在点击时制作 scrollView 'bounce',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27599338/