|
我最近在做一个ios项目,遇到一个问题就是需要在一个地图上画出路线。地图图片用UIImage存在一个UIImageView上面,我是想在UIImageView上添加一个UIView,需要将UIView大小和UIImage大小保持一样, 然后在UIView上调用drawrect方法画线 这么做了没有生效 求助。 @property (weak, nonatomic) IBOutlet NAMapView *mapView; [self.view addSubview:self.mapView]; [self.mapView setNeedsDisplay]; 在NAMapView中,我们有一个UIImageView存储地图图片,ShowRouteView是一个UIView,用来调用drawrect方法画路线 @property (nonatomic,strong) ShowRouteView *showrouteview;
_showrouteview = [[UIView alloc] initWithFrame:CGRectZero];
[self addSubview:self.showrouteview];
- (void)drawRect:(CGRect)rect{
NSLog(@"mapview");
[self.showrouteview setNeedsDisplay];
}
在ShowRouteView类中有drawrect方法如下 - (void)drawRect:(CGRect)rect {
NSLog(@"routeview");
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetLineWidth(context, 1.0);
CGContextSetRGBStrokeColor(context, 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 100, 100);
CGContextAddLineToPoint(context, 0, 150);
CGContextAddLineToPoint(context, 50, 180);
CGContextStrokePath(context);
}
最终console里显示,UIView里的drawrect方法没有被调用。求助~ |
|
| 100分 |
frame 是不是 CGRectZero ?如果是 Zero,是不会调用的
|