Convert MKAnnotation Coordinates to View Coordinates

前端 未结 2 590
旧时难觅i
旧时难觅i 2021-01-21 01:54

I am displaying a custom UIView when the user clicks on the pin (Like the Zillow app). Now the problem is that I need to place the view right above the actual pin. The MKAnnotat

2条回答
  •  遥遥无期
    2021-01-21 02:12

    This is perfect, but there is one little problem. If you use a different image to your Pin, than you will need make a correction to Your view Appoint to center of your pin. Like this

    UIView *view = ...
    CGPoint p = [mv convertCoordinate:annotation.coordinate toPointToView:mv];
    CGRect frame = CGRectMake(p.x - (view.frame.size.width/2), 
                              p.y- (view.frame.size.height / 2),
                              view.frame.size.width,
                              view.frame.size.height);
    view.frame = frame;
    [self.view addSubView:view];
    

提交回复
热议问题