Как позволить drawRect получать значение точек из ViewController и рисовать?

Я создал класс newView из UIView и стремлюсь нарисовать четырехугольник. 4 конуса (ClipPointA, ClipPointB, ClipPointC, ClipPointD) четырехугольника должны считывать значение из ViewController.

новыйView.h:

@interface newView : UIView {
    CGPoint ClipPointA, ClipPointB, ClipPointC, ClipPointD; 
}
@end

новый вид.м:

@implementation newView

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code.
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    // Drawing code.
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 0.0, 1.0);    
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, ClipPointA.x, ClipPointA.y); //start point
    CGContextAddLineToPoint(context, ClipPointB.x, ClipPointB.y);
    CGContextAddLineToPoint(context, ClipPointD.x, ClipPointD.y); 
    CGContextAddLineToPoint(context, ClipPointC.x, ClipPointC.y); // end path   
    CGContextClosePath(context); // close path  
    CGContextSetLineWidth(context, 2.0); 
    CGContextStrokePath(context); 
}

- (void)dealloc {
    [super dealloc];
}

@end

Я создал экземпляр newView в ViewController. Как мне написать следующую часть кода, чтобы 4 CGPoints читали значение из ViewController?

Спасибо.


person Nauhc    schedule 25.04.2011    source источник


Ответы (1)


когда вы создаете новый UIView, пожалуйста, передайте баллы также, например: пусть A, B, C, D будут вашими 4 баллами

newView *nv =[[dragman alloc]initWithFrame:self.view.frame];
    nv.ClipPointA=A;
    nv.ClipPointB=B;
        nv.ClipPointC=C;
        nv.ClipPointD=D;
    [nv setUserInteractionEnabled:YES];
    [contentView addSubview:nv];
    [nv release];
person Lena    schedule 25.04.2011