DrawRect没有显示形状?

时间:2013-04-26 02:38:09

标签: ios objective-c uiview uiviewcontroller

我目前正在尝试同时实现两个子类。

我在viewController中使用UIViewController <CLLocationManagerDelegate>子类来处理gps。使用UIView子类绘制时。

这是我的代码摘要:

MapViewController.h:

@interface MapViewController: UIViewController <CLLocationManagerDelegate>{
DrawCircle *circleView;
}

@property (nonatomic, retain) DrawCircle *circleView;
@end

DrawCircle.h:

@interface DrawCircle : UIView
-(void)addPoint:(CGPoint)point;
@end

我在这里要做的是让DrawCircle成为MapViewController的一个属性。但是我仍然没有在屏幕上画任何东西。

如果它有帮助,这是我的DrawCircle.m代码:

-(id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        _points = [[NSMutableArray alloc] init];
    }
    return self;
}

-(void)addPoint:(CGPoint)point {
    //Wrap the point in an NSValue to add it to the array
    [_points addObject:[NSValue valueWithCGPoint:point]];
    //This will tell our view to redraw itself, calling drawRect
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    for(NSValue *pointValue in _points) {
        CGPoint point = [pointValue CGPointValue];
        CGContextAddEllipseInRect(ctx, CGRectMake(point.x - 10, point.y - 10, 20, 20));
    }

    CGContextSetFillColor(ctx, CGColorGetComponents([[UIColor redColor] CGColor]));
    CGContextFillPath(ctx);
}

另外,作为最后一点信息,我可以给大家。这是我的地图视图控制器场景的快照。 MapViewController Scene

我感觉形状正在被绘制,但却被某种方式掩盖了。

我还想提一下,如果这很邋and且难以理解,我很抱歉。我非常擅长客观c并为iOS开发,所以请光临我。

修改 经过进一步调查,我的UIImage似乎正在绘制正在绘制的形状。我只是弄乱了并移除了UIImage,我的形状就在那里。现在的问题是,我如何“回到”我的UIImage,以便我的形状在前面?

0 个答案:

没有答案