0

これは私のコードです:

@implementation myView2
{
BOOL _touchHasBegun;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_touchHasBegun = YES;
}

- (void)drawRect:(CGRect)rect
{
if (_touchHasBegun == YES)
{
    NSLog(@"fjnv");
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetRGBStrokeColor(context, 0, 0, 225, 1);
    CGContextSetRGBFillColor(context, 0, 0, 255, 1);
    CGRect rectangle = CGRectMake(50, 50, 500, 500);
    CGContextStrokeEllipseInRect(context, rectangle);
}
}

私はまた、UIButton上にボタンアクションメソッドUIViewを設定してみました。CGRectしかし、それはうまくいきません。このコードもそうではありません。どうしたの?

4

1 に答える 1

0

ここに作業スニペットがあります:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    _touchHasBegan = YES;
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    if(_touchHasBegan){
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetRGBStrokeColor(context, 0, 0, 225, 1);
        CGContextSetRGBFillColor(context, 0, 0, 255, 1);
        CGRect rectangle = self.bounds;
        CGContextStrokeEllipseInRect(context, rectangle);
    }
}
于 2013-02-26T21:59:59.823 に答える