Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

CDVGestureHandler.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import "CDVGestureHandler.h"
  18. @implementation CDVGestureHandler
  19. - (void)pluginInitialize
  20. {
  21. [self applyLongPressFix];
  22. }
  23. - (void)applyLongPressFix
  24. {
  25. // You can't suppress 3D Touch and still have regular longpress,
  26. // so if this is false, let's not consider the 3D Touch setting at all.
  27. if (![self.commandDelegate.settings objectForKey:@"suppresseslongpressgesture"] ||
  28. ![[self.commandDelegate.settings objectForKey:@"suppresseslongpressgesture"] boolValue]) {
  29. return;
  30. }
  31. self.lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
  32. self.lpgr.minimumPressDuration = 0.45f;
  33. self.lpgr.allowableMovement = 200.0f;
  34. // 0.45 is ok for 'regular longpress', 0.05-0.08 is required for '3D Touch longpress',
  35. // but since this will also kill onclick handlers (not ontouchend) it's optional.
  36. if ([self.commandDelegate.settings objectForKey:@"suppresses3dtouchgesture"] &&
  37. [[self.commandDelegate.settings objectForKey:@"suppresses3dtouchgesture"] boolValue]) {
  38. self.lpgr.minimumPressDuration = 0.15f;
  39. }
  40. NSArray *views = self.webView.subviews;
  41. if (views.count == 0) {
  42. NSLog(@"No webview subviews found, not applying the longpress fix.");
  43. return;
  44. }
  45. for (int i=0; i<views.count; i++) {
  46. UIView *webViewScrollView = views[i];
  47. if ([webViewScrollView isKindOfClass:[UIScrollView class]]) {
  48. NSArray *webViewScrollViewSubViews = webViewScrollView.subviews;
  49. UIView *browser = webViewScrollViewSubViews[0];
  50. [browser addGestureRecognizer:self.lpgr];
  51. break;
  52. }
  53. }
  54. }
  55. - (void)handleLongPressGestures:(UILongPressGestureRecognizer*)sender
  56. {
  57. }
  58. @end