Ios UIImageView地图视图的子视图
我必须添加一个ImageView作为MapView的子视图。我不能用代码来做,因为ImageView总是落在mapView后面。我不能在IB中这样做,因为在文件的所有者中,UIImageView始终是映射视图的外部视图(我尝试了好几次)。我使用的是Xcode 4.5。我可以添加UIImageView作为MapView的子视图吗 这是MapViewController.h中的代码Ios UIImageView地图视图的子视图,ios,uiimageview,mkmapview,addsubview,Ios,Uiimageview,Mkmapview,Addsubview,我必须添加一个ImageView作为MapView的子视图。我不能用代码来做,因为ImageView总是落在mapView后面。我不能在IB中这样做,因为在文件的所有者中,UIImageView始终是映射视图的外部视图(我尝试了好几次)。我使用的是Xcode 4.5。我可以添加UIImageView作为MapView的子视图吗 这是MapViewController.h中的代码 @property (nonatomic, strong) UIImageView *iphoneLegenda;
@property (nonatomic, strong) UIImageView *iphoneLegenda;
@property (nonatomic, strong)IBOutlet MKMapView *mapView;
在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];
//.....
}
如果您希望将imageview放在地图视图的顶部,请参见您正在使用的xib。mapview已经在一个视图上,只需像mapview一样在xib中添加imageview,并将其链接起来。使该alpha在xib中具有0(更好地用于以后的动画)。然后在你的代码中,我假设你想要一个按钮或者某种东西来打开它。 所以换一条线,让我离开
@property (nonatomic, strong) IBOutlet UIImageView *iphoneLegenda;
然后是淡入的动作:
[UIView animateWithDuration:0.5 animations:^{
[iphoneLengenda setAlpha:1.];
}];
如果您想让imageview位于地图视图的顶部,就不必费心设置边框等。,因为您正在使用xib。mapview已经在一个视图上,只需像mapview一样在xib中添加imageview,并将其链接起来。使该alpha在xib中具有0(更好地用于以后的动画)。然后在你的代码中,我假设你想要一个按钮或者某种东西来打开它。 所以换一条线,让我离开
@property (nonatomic, strong) IBOutlet UIImageView *iphoneLegenda;
然后是淡入的动作:
[UIView animateWithDuration:0.5 animations:^{
[iphoneLengenda setAlpha:1.];
}];
不必费心设置框架等。这个方案怎么样:
UIView
- MKMapView
- UIImageView
MKMapView的大小将与UIView相同,UIImageView将始终位于顶部。此方案如何:
UIView
- MKMapView
- UIImageView
MKMapView的大小将与UIView相同,UIImageView将始终位于顶部。我认为AntonPalich和MashDup的答案是最好的方法。 要在mapView中添加子视图,必须添加QuartzCore.framework,代码如下:
- (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];
}
我认为AntonPalich和MashDup的答案是最好的方法。 要在mapView中添加子视图,必须添加QuartzCore.framework,代码如下:
- (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];
}
为什么要在mapview中使用UIImageView?此代码错误[self.iphoneLegenda-bringsubview-tofront:self.mapView];,它应该是[self.mapView-bringsubview-tofront:self.iphoneLegenda];为什么要在mapview中使用UIImageView?此代码错误[self.iphoneLegenda-bringsubview-tofront:self.mapView];,它应该是[self.mapView-bringsubview-tofront:self.iphoneLegenda];