Centering MKMapView on spot N-pixels below pin

前端 未结 8 1423
梦毁少年i
梦毁少年i 2020-11-30 02:34

Want to center MKMapView on a point N-pixels below a given pin (which may or may not be visible in the current MapRect).

I\'ve been trying

8条回答
  •  一生所求
    2020-11-30 03:11

    One easy solution is that you make the frame of your map view larger than the visible area. Then position your pin in the center of the map view and hide all the unwanted areas behind another view or outside of the screen bounds.

    Let me elaborate. If I look at your screen shot, do the following:

    The distance between you pin and the bottom is 353 pixel. So make your map views frame twice the height: 706 pixel. You screenshot has a height of 411 pixel. Position your frame at an origin of 706px - 411px = -293 pixel. Now center your map view at the coordinate of the pin and you are done.

    Update 4-March-2014:

    I created a small sample application with Xcode 5.0.2 to demo this: http://cl.ly/0e2v0u3G2q1d

提交回复
热议问题