您的位置:首页 > 其它

setNeedsDisplay为什么没有用?(按需结贴 肯定有分)

2017-01-08 17:27 465 查看
#import <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>

#define PI 3.14159265358979323846

@implementation GameView

int msa=100,msb=100, mea=200,meb=200;
//初始化两个圆的中心点

- (IBAction)next:(id)sender {

    int msa = 200;

    int msb = 200;

    int mea = 100;

    int meb = 100;

 [_gameview setNeedsDisplay];

 }
//想做的事情,点击按钮后改变两个圆的坐标,并重新加载DrawRect

-(void) drawRect:(CGRect)rect

{   

    [Drawing drawStartpoint:msa :msb];

    [Drawing drawEndpoint:mea :meb];

 }
//下面是画两个圆的类和方法

#import "Drawing.h"

+(void) drawStartpoint:(int)a :(int)b

{

    

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextSetRGBFillColor(context, 1, 0, 0, 1);

    

    CGContextAddArc(context, a, b, 20, 0, 2*PI, 0); //添加一个圆

    

    CGContextDrawPath(context, kCGPathFill);//绘制填充}

}

+(void) drawEndpoint:(int)a :(int)b

{

    

    CGContextRef context = UIGraphicsGetCurrentContext();

    

    CGContextSetRGBFillColor(context, 0, 1, 0, 1);

    

    CGContextAddArc(context, a, b, 20, 0, 2*PI, 0); //添加一个圆

    

    CGContextDrawPath(context, kCGPathFill);//绘制填充}

}

为什么点击按钮后没有反应?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: