简体   繁体   中英

Make MKMapView of Circular shape in ios?

I am working on a app where I have to make Map using MKMapView , but with circular shape?

Any idea about this, any clue would be helpful too.

See in the screen shoot, you will get an idea what I am asking about.

See the Map in circle.

查看圈子中的地图

Here's a tricky way, but it may be you want to!

Add QuartzCore.framework

#import <QuartzCore/QuartzCore.h>

//make circled shape

[yourMapView.layer setMasksToBounds:YES];
[yourMapView.layer setCornerRadius:160.0]; //here you've to pass width of yourMapView / 2

Excited to see more answers!! :)

First, if you do this while using satellite/aerial photographs you will violate the Google Maps Terms of Service .

10 License Restrictions. Except as expressly permitted under the Terms, or unless you have received prior written authorization from Google (or, as applicable, from the provider of particular Content), Google's licenses above are subject to your adherence to all of the restrictions below. Except as explicitly permitted in Section 7, you must not (nor may you permit anyone else to):

...

10.7 delete, obscure, or in any manner alter any warning, notice (including but not limited to any copyright or other proprietary rights notice), or link that appears in the Service or the Content;

Any circular MKMapView will probably obscure the copyright notice that displays with photographs.

We may expect MKMapView will soon change from using Google data to Apple data, but there will probably be similar text that you must not obscure.


With that out of the way, there are two ways you can make this work:

  1. Create a UIView subclass with a transparent background, make its drawRect method draw around a circular hole, and make its pointInside:withEvent: method return NO for the same hole. Place one of these views on top of your MKMapView .
  2. Create a CAShapeLayer with an opaque circle (or any other shape) and make it the mask of the MKMapView 's own layer . This will allow the circular map to appear anywhere, but it will still be possible to interact with its invisible corners.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM