1

**Here First, We create custom Annotation view which contain image, button and other information. We put onto the Map as a image marker.Here we also hide Call out view.

Second condition only contain map marker image and display Call out view. Right now, issue is if Call out view open and then we click on custom view It's required Double tap.

We reviewed that first click into call Map deselect method then after we getting button tap event.

If we click only different call out view or different custom image marker view then it is working on single tap.In this scenario, How can i handle both cases in single tap?**

//Add image marker
  -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
            {
                if([annotation isKindOfClass:[MKUserLocation class]])
                    return nil;

                int ID = [((NewClass *)annotation).uniqueID intValue];

                static NSString *identifier = @"myAnnotation";

                annotationView = (CustomAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

               if (!annotationView)
                {
                    annotationView = [[CustomAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
                    annotationView.image = [UIImage imageNamed:@"profilemarker.png"];
                    annotationView.canShowCallout=NO;
                }
                else {
                    annotationView.annotation = annotation;
                }

                    if(array_Profiles[ID][@"id"])
                    {
                        NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
                        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

                        NSDate *startDate = [dateFormatter dateFromString:array_Profiles[ID][@"start_time"]];
                        NSDate *endDate = [dateFormatter dateFromString:array_Profiles[ID][@"end_time"]];

                         annotationView.image = nil;

        **//Here Add Custom Annotation view. View contains add two Image view and Button. Here we hide annotationView.canShowCallout=NO** 

                        LiveProfileMarker *liveProMarkerView = (LiveProfileMarker *)[[[NSBundle mainBundle] loadNibNamed:@"LiveProfileMarker" owner:self options:nil] objectAtIndex:0];
                        liveProMarkerView.delegate = self;
                        CGRect liveViewFrame = liveProMarkerView.frame;
                        liveViewFrame.origin = CGPointMake(-liveViewFrame.size.width/2 + 15, -liveViewFrame.size.height);
                        liveProMarkerView.backgroundColor=[UIColor clearColor];
                        liveProMarkerView.frame = liveViewFrame;

                        if(([[NSDate date] compare: startDate] ==  NSOrderedDescending) && ([[NSDate date] compare: endDate] == NSOrderedAscending))
                            //Set Profile marker for live
                                [liveProMarkerView.img_banner setImage:[UIImage imageNamed:@"live_trans_banner.png"]];
                        else
                                [liveProMarkerView.img_banner setImage:nil];

                        [liveProMarkerView.img_ProfileIV setFrame:CGRectMake(5, 5, liveViewFrame.size.width-10, liveViewFrame.size.height-15)];
                        [liveProMarkerView.img_ProfileIV setImageWithURL:[NSURL URLWithString:array_Profiles[ID][@"logo"]] placeholderImage:nil];
                        liveProMarkerView.profile_Btn.tag = ID;
                        [annotationView addSubview:liveProMarkerView];
                        liveProMarkerView.annotationVI = annotationView;

                        annotationView.canShowCallout=NO;

                    }
                    else
                    {
                        annotationView.image = [UIImage imageNamed:@"profilemarker3.png"];

                        if([isFlyer intValue] == 0)
                        {
                            UIButton * btn_AssessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                            [btn_AssessoryView setTag:ID];
                            [btn_AssessoryView addTarget:self action:@selector(PinAnnoation:) forControlEvents:UIControlEventTouchUpInside];

                            [annotationView setRightCalloutAccessoryView:btn_AssessoryView];

                            //Changes Make Here
                            UIImageView * imageView = [[UIImageView alloc] init];
                           // AsyncImageView * imageView = [[AsyncImageView alloc] init];
                            [imageView setContentMode:UIViewContentModeScaleAspectFit];

                            if([array_Profiles[ID][@"logo"] length] == 0)
                            {
                                [imageView setFrame:CGRectMake(0, 0, 41, 30)];
                                [imageView setImage:[UIImage imageNamed:@"fly.png"]];
                            }
                            else
                            {
                                [imageView setFrame:CGRectMake(0, 0, 30, 30)];
                               // [imageView setImageWithURL:[NSURL URLWithString:array_Profiles[ID][@"logo"]] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
                               // [imageView setImageURL:[NSURL URLWithString:array_Profiles[ID][@"logo"]]];
                               // imageView.showActivityIndicator = YES;

                                [imageView setImageWithURL:[NSURL URLWithString:array_Profiles[ID][@"logo"]] placeholderImage:nil];
                            }

                            annotationView.leftCalloutAccessoryView = imageView;

                        }

      //Add here image in annotation view and show Call Out
                        annotationView.canShowCallout=YES;
                    }

                return annotationView;
            }

    - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)viewmap
    {

        for (UIView *subView in calloutView.subviews){

            if ([subView isKindOfClass:[UIView class]]) {
                [subView removeFromSuperview];
            }
        }

    }



    //De Select View
    - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
    {

        for (UIView *subView in calloutView.subviews){

            if ([subView isKindOfClass:[UIView class]]) {
                [subView removeFromSuperview];
            }
        }

    }


    //Below delegate method for Live Profile view Button Action

    -(void)ProfileButtonAction:(NSString *)markerID SelectedAnnotationView:(MKAnnotationView *)annotationObj profileMarkerFrame:(CGRect)frame{
       // NSLog(@"markerID : %@",markerID);

        for (UIView *subView in calloutView.subviews){

            if ([subView isKindOfClass:[UIView class]]) {
                [subView removeFromSuperview];
            }
        }

        NSMutableArray *annotAry = [[NSMutableArray alloc] init];
        [annotAry addObject:annotationObj];


        MKAnnotationView *viewmap = annotationObj;

        if(![viewmap.annotation isKindOfClass:[MKUserLocation class]])
        {
            NewClass *ann=(NewClass *)viewmap.annotation;

            [_mapView setCenterCoordinate:ann.coordinate animated:YES];

            int ID = [markerID intValue];

            if(array_Profiles[ID][@"id"]){

                calloutView = (CalloutView *)[[[NSBundle mainBundle] loadNibNamed:@"CalloutView" owner:self options:nil] objectAtIndex:0];

                calloutView.delegate=self;
                calloutView.backgroundColor=[UIColor clearColor];
                CGRect calloutViewFrame = calloutView.frame;
                calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, (frame.origin.y-calloutViewFrame.size.height));
                calloutView.frame =calloutViewFrame;

                calloutView.lbl_title.text=array_Profiles[ID][@"name"];
                calloutView.lbl_description.text=array_Profiles[ID][@"offer1"];
                calloutView.btn_click.tag=ID;

                NSArray *startArr=[api_CommonMethods tocanizeTheString:array_Profiles[ID][@"start_time"] tocan:@" "];
                NSArray *endArr=[api_CommonMethods tocanizeTheString:array_Profiles[ID][@"end_time"] tocan:@" "];

                NSString *startT=startArr[1];
                startT=[startT substringToIndex:startT.length-3];
                NSString *endT=endArr[1];
                endT=[endT substringToIndex:endT.length-3];
                NSString *timings=[NSString stringWithFormat:@"%@-%@",startT,endT];

                calloutView.lbl_timings.text=timings;

                [viewmap addSubview:calloutView];
            }

        }

    }
iOS Dev
  • 115
  • 7

0 Answers0