【问题标题】:Adding Shadows to MKMapView为 MKMapView 添加阴影
【发布时间】:2011-01-24 17:10:00
【问题描述】:

我有一个 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;
}

我明白了:

我做错了吗?

【问题讨论】:

    标签: iphone ios mkmapview shadow


    【解决方案1】:

    感谢: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)];
    

    【讨论】:

      【解决方案2】:

      另一种选择(实际上建议的解决方案对我不起作用,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 开发者,您可以在此处查看实际结果 here。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-25
        • 2019-08-12
        • 2014-10-10
        • 2015-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多