I must add an ImageView as subview of MapView. I can not do it by code, because the ImageView always ends up behind the mapView. I can not do it in IB because in the file's owner the UIImageView is always external respect to the mapView ( I tried several times).I am using Xcode 4.5. Can I add a UIImageView as subview of MapView?
this is the code in MapViewController.h
@property (nonatomic, strong) UIImageView *iphoneLegenda;
@property (nonatomic, strong)IBOutlet MKMapView *mapView;
in MapViewController.m
@synthesize iphoneLegenda;
@synthesize mapView;
- (void)viewDidLoad
{
//.....
self.iphoneLegenda.frame = CGRectMake(self.mapView.bounds.origin.x,
self.mapView.bounds.origin.y, 200, 100);
//......
[self.mapView addSubview:self.iphoneLegenda];
[self.iphoneLegenda bringSubviewToFront:self.mapView];
//.....
}
I think the answers of AntonPalich and MashDup are the best way. To add a subview inside mapView you have to add QuartzCore.framework and this is the code:
- (void)viewDidLoad
{
CALayer *layer = [CALayer layer];
layer.backgroundColor = [[UIColor whiteColor] CGColor];
layer.bounds = CGRectMake(mapView.frame.origin.x, mapView.frame.origin.y, 200, 100);
[[mapView layer] addSublayer:layer];
}
If you want the imageview on top of the map view, seeing as you are using an xib. the mapview is already on a view, just add the imageview in the xib like you have for the mapview and link that up. Make that alpha have 0 (better for animation later) in the xib. Then in your code, I assume you want a button or some sorts to turn it on. So change the line have iboutlet.
@property (nonatomic, strong) IBOutlet UIImageView *iphoneLegenda;
Then an action to fade it in:
[UIView animateWithDuration:0.5 animations:^{
[iphoneLengenda setAlpha:1.];
}];
Dont have to mess about setting frames etc.
How about this scheme:
UIView
- MKMapView
- UIImageView
MKMapView will be same size as UIView and UIImageView will be always at top.
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.