Advertisement
undeadhip

Untitled

Aug 1st, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NSMutableArray *_bubbleScreenAnimations;
  2. - (void)selectAnnotation:(EBXPointAnnotation *)annotation {
  3. //    self.bubbleView.scrollEnabled = NO;
  4.     [self.bubbleView hide];
  5.    
  6.     self.scrolling = YES;
  7.     self.mapView.userInteractionEnabled = NO;
  8.     [self updateAnnotationForEvent:self.selectedEvent];
  9.    
  10.     //Giving time to update annotations
  11.     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  12.         dispatch_async(dispatch_get_main_queue(), ^{
  13.             MKAnnotationView *view = [self.mapView viewForAnnotation:annotation];
  14.             self.annotationView = view;
  15.             view.image = [UIImage imageNamed:@"emptyYellowAnnotation"];
  16.            
  17.             annotation.selected = YES;
  18.            
  19.             MKMapRect r = [self.mapView visibleMapRect];
  20.             MKMapPoint pt = MKMapPointForCoordinate([annotation coordinate]);
  21.             r.origin.x = pt.x - r.size.width * 0.5;
  22.            
  23.             double yRatio = 392.0 / self.mapView.frame.size.height;
  24. //            r.origin.y = pt.y - r.size.height * 0.74409;
  25.             r.origin.y = pt.y - r.size.height * yRatio;
  26.            
  27.             CGFloat epsilon = 1e-01;
  28.             BOOL xEqual =   r.origin.x < [self.mapView visibleMapRect].origin.x + epsilon &&
  29.             r.origin.x > [self.mapView visibleMapRect].origin.x - epsilon;
  30.             BOOL yEqual =   r.origin.y < [self.mapView visibleMapRect].origin.y + epsilon &&
  31.             r.origin.y > [self.mapView visibleMapRect].origin.y - epsilon;
  32.            
  33.             if (xEqual && yEqual) {
  34.                 [self.mapView setVisibleMapRect:r animated:NO];
  35.                 [self presentBubbleScreenAnimation];
  36.             }
  37.             else {
  38.                 if (!_bubbleScreenAnimations) {
  39.                     _bubbleScreenAnimations = [NSMutableArray array];
  40.                 }
  41.                
  42.                 [_bubbleScreenAnimations addObject:[NSObject new]];
  43.                 [self.mapView setVisibleMapRect:r animated:YES];
  44.                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  45.                     if ([_bubbleScreenAnimations count] <= 1) {
  46.                         [self presentBubbleScreenAnimation];
  47.                     }
  48.                    
  49.                     [_bubbleScreenAnimations removeLastObject];
  50.                 });
  51. //                [UIView animateWithDuration:0.6 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
  52. //                    [self.mapView setVisibleMapRect:r];
  53. //                } completion:^(BOOL finished) {
  54. //                    if (finished) {
  55. //                        [self presentBubbleScreenAnimation];
  56. //                    }
  57. //                }];
  58.             }
  59.         });
  60.     });
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement