[英]How do I add a UIView on top of a MKAnnotationView and then display it on a MKMapView?
[英]How do I crop a MKMapView (or any UIView) into a custom shape?
我正在嘗試通過以下方式調整MKMapView的大小:
元素應該能夠出現在頂部的圓弧后面,因此該視圖似乎不是正方形的。 我知道使用CALayer應該可以,但是也許有人以前做過?
如果將MKMapView放在UIView中,然后對其應用蒙版,則應該很有可能。
這是一個非常(!)基本示例:
我所做的只是將地圖放入名為“ mapContainer”的UIView中,並使用以下方法為其添加了蒙版:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect rect = CGRectInset(self.view.frame, 70, 70);
UIView* newView = [[UIView alloc] initWithFrame:rect];
newView.layer.cornerRadius = 55.0;
newView.backgroundColor = [UIColor redColor];
self.mapContainer.layer.mask = newView.layer;
}
您可以為其添加邊框...
..還有幾行...
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
CGRect rect = CGRectInset(self.view.frame, 70, 70);
UIView* newView = [[UIView alloc] initWithFrame:rect];
newView.layer.cornerRadius = 55.0;
newView.backgroundColor = [UIColor redColor];
UIView* borderView = [[UIView alloc] initWithFrame:rect];
borderView.backgroundColor = [UIColor clearColor];
borderView.layer.cornerRadius = 55.0;
borderView.layer.borderWidth = 3.0;
borderView.layer.borderColor = [[UIColor redColor] CGColor];
[self.mapContainer addSubview:borderView];
[self.mapContainer bringSubviewToFront:borderView];
self.mapContainer.layer.mask = newView.layer;
}
我希望這可以為您指明正確的方向。
與Apple Maps不同。
;-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.