例如,在iOS 7/8锁定屏幕上,如果您点击而不是将其向右拖动,它将产生轻微的弹跳效果。如何检测轻击手势(不要与拖动混淆)并重新创建类似的“弹跳”效果?任何人都可以共享一个代码示例(swift / obj-c)吗?
我认为这是向用户显示应该拖动而不是轻按的好方法,并且不需要读取任何小指示器。
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;
}];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句