CCHFadeInOutMapAnimator.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // CCHFadeInOutMapAnimator.m
  3. // CCHMapClusterController
  4. //
  5. // Copyright (C) 2013 Claus Höfele
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. #import "CCHFadeInOutMapAnimator.h"
  26. #import "CCHMapClusterController.h"
  27. #import <MapKit/MapKit.h>
  28. @implementation CCHFadeInOutMapAnimator
  29. - (instancetype)init
  30. {
  31. self = [super init];
  32. if (self) {
  33. _duration = 0.2;
  34. }
  35. return self;
  36. }
  37. - (void)mapClusterController:(CCHMapClusterController *)mapClusterController didAddAnnotationViews:(NSArray *)annotationViews
  38. {
  39. // Animate annotations that get added
  40. #if TARGET_OS_IPHONE
  41. for (MKAnnotationView *annotationView in annotationViews)
  42. {
  43. annotationView.alpha = 0.0;
  44. }
  45. [UIView animateWithDuration:self.duration animations:^{
  46. for (MKAnnotationView *annotationView in annotationViews) {
  47. annotationView.alpha = 1.0;
  48. }
  49. }];
  50. #endif
  51. }
  52. - (void)mapClusterController:(CCHMapClusterController *)mapClusterController willRemoveAnnotations:(NSArray *)annotations withCompletionHandler:(void (^)(void))completionHandler
  53. {
  54. #if TARGET_OS_IPHONE
  55. MKMapView *mapView = mapClusterController.mapView;
  56. [UIView animateWithDuration:self.duration animations:^{
  57. for (id<MKAnnotation> annotation in annotations) {
  58. MKAnnotationView *annotationView = [mapView viewForAnnotation:annotation];
  59. annotationView.alpha = 0.0;
  60. }
  61. } completion:^(BOOL finished) {
  62. if (completionHandler) {
  63. completionHandler();
  64. }
  65. }];
  66. #else
  67. if (completionHandler) {
  68. completionHandler();
  69. }
  70. #endif
  71. }
  72. @end