向 MKMapView 添加阴影

发布于 2024-10-14 11:13:01 字数 418 浏览 3 评论 0原文

我有一个 MapView,我想添加它一个投影,但我尝试的方法不起作用:

- (void)viewDidLoad {
    [super viewDidLoad];

    mapView.layer.shadowColor = [[UIColor blackColor] CGColor]; 
    mapView.layer.shadowOffset = CGSizeMake(10.0f, 10.0f);
    mapView.layer.shadowOpacity = 1.0f;
    mapView.layer.shadowRadius = 10.0f;
}

我得到这个:

“示例”

我做错了什么吗?

I've a MapView, and I want to add it a dropshadow, but the method I tried doesn't work:

- (void)viewDidLoad {
    [super viewDidLoad];

    mapView.layer.shadowColor = [[UIColor blackColor] CGColor]; 
    mapView.layer.shadowOffset = CGSizeMake(10.0f, 10.0f);
    mapView.layer.shadowOpacity = 1.0f;
    mapView.layer.shadowRadius = 10.0f;
}

I get this:

example

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫漫岁月 2024-10-21 11:13:01

解决感谢:http://blog.amarkulo.com/create-rounded-uiviews -with-shadow

使用此代码:

[[mapView layer] setMasksToBounds:NO];
[[mapView layer] setShadowColor:[UIColor blackColor].CGColor];
[[mapView layer] setShadowOpacity:1.0f];
[[mapView layer] setShadowRadius:6.0f];
[[mapView layer] setShadowOffset:CGSizeMake(0, 3)];

Resolved thanks to: http://blog.amarkulo.com/create-rounded-uiviews-with-shadow

using this code:

[[mapView layer] setMasksToBounds:NO];
[[mapView layer] setShadowColor:[UIColor blackColor].CGColor];
[[mapView layer] setShadowOpacity:1.0f];
[[mapView layer] setShadowRadius:6.0f];
[[mapView layer] setShadowOffset:CGSizeMake(0, 3)];
心如荒岛 2024-10-21 11:13:01

另一种替代方案(实际上建议的解决方案对我不起作用,iOS SDK 4.3)是将 MKMapView 包含在 UIView 中:

_mapContainer = [[UIView alloc] initWithFrame: CGRectMake (0.0f, 44.0f, 320.0f, container.frame.size.height - 44.0f)];
_mapContainer.autoresizingMask = UIViewAutoresizingFlexibleHeight;
_mapContainer.layer.masksToBounds = NO;
_mapContainer.layer.shadowColor = [UIColor blackColor].CGColor;
_mapContainer.layer.shadowOffset = CGSizeMake (0.0f, 10.0f);
_mapContainer.layer.shadowOpacity = 0.6f;
_mapContainer.layer.shadowRadius = 5.0f;
[container addSubview: _mapContainer];
[_mapContainer release];

_mapView = [[MKMapView alloc] initWithFrame: _mapContainer.bounds];
_mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[_mapContainer addSubview: _mapView];
[_mapView release];

这样您还可以对 _mapContainer 的框架进行动画处理,并仍然将阴影保持在正确的位置。

如果您是注册的 Apple 开发者,您可以在此处查看实际结果。

Another alternative (actually the proposed solution didn't work for me, iOS SDK 4.3) is to enclose the MKMapView in a UIView:

_mapContainer = [[UIView alloc] initWithFrame: CGRectMake (0.0f, 44.0f, 320.0f, container.frame.size.height - 44.0f)];
_mapContainer.autoresizingMask = UIViewAutoresizingFlexibleHeight;
_mapContainer.layer.masksToBounds = NO;
_mapContainer.layer.shadowColor = [UIColor blackColor].CGColor;
_mapContainer.layer.shadowOffset = CGSizeMake (0.0f, 10.0f);
_mapContainer.layer.shadowOpacity = 0.6f;
_mapContainer.layer.shadowRadius = 5.0f;
[container addSubview: _mapContainer];
[_mapContainer release];

_mapView = [[MKMapView alloc] initWithFrame: _mapContainer.bounds];
_mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[_mapContainer addSubview: _mapView];
[_mapView release];

This way you can also animate the frame of the _mapContainer and still keep the shadow in its correct place.

Here you can see actual results here, if you're a registered Apple developer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文