ios - 如何在点击时制作 scrollView 'bounce'

标签 ios objective-c swift

例如在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/

相关文章:

objective-c - 如何将 MIME 类型转换为 iOS 上的首选文件扩展名?

ios - 从单元测试执行时未在控制台中打印 Struct 的说明

ios - fatal error : Unexpectedly found nil while unwrapping an Optional value (lldb)

ios - 如何从另一种方法重新加载 Tableview 数据

iphone - iOS 5.1 : -[UIColor colorWithPatternImage:] background color draws solid black

ios - Alamofire 4 多部分请求上传进度

iphone - CTFrameGetLineOrigins的来源不正确

objective-c - 数据库错误 : property not found on object of type

ios - 如何停止 CATransform3DMakeScale 动画缩放变化?

ios - Firebase 在 Swift 中使用 PromiseKit/AwaitKit 调用永远不会返回