2011-01-24 35 views
5

Tengo un MapView, y quiero añadir un dropshadow, pero el método Intenté no funciona:añadir sombras a MKMapView

- (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; 
} 

me sale esto:

example

¿Estoy haciendo algo mal?

Respuesta

9

gracias decididos a: http://blog.amarkulo.com/create-rounded-uiviews-with-shadow

utilizando este código:

[[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

Otra alternativa (en realidad la solución propuesta no funcionó para mí, iOS SDK 4.3) es para encerrar el MKMapView en un 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]; 

esta manera también se puede animar el marco de la _mapContainer y aún así mantener la sombra en su lugar correcto.

Aquí puede ver los resultados reales here, si usted es un desarrollador registrado de Apple.