setNeedsDisplay为什么没有用?(按需结贴 肯定有分)
2017-01-08 17:27
507 查看
#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);//绘制填充}
}
为什么点击按钮后没有反应?
#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);//绘制填充}
}
为什么点击按钮后没有反应?
相关文章推荐
- setNeedsDisplay为什么没有用?(按需结贴 肯定有分)
- skb的两个函数pskb_copy和skb_copy
- asp 排序问题?
- SecureCRT连接虚拟机的ubuntu
- AsyncTask如何使用(集大众智慧)
- AndroidStudio2.0 写setOnclickListener的时候警告,需要判断view是否为空,大家觉得有必要吗
- Android开发中数据库没关闭怎么办
- 快速驶来的智能出行交通工具,未来去哪?
- Android 求 商城app中,物品加入购物车的特效代码,或者相关的例子。
- Apache添加虚拟主机目录
- mysql 自增长 AUTO_INCREMENT
- Unity3d 使用 RSA和DES 加密网络数据包
- POJ 2393 Yogurt factory__贪心
- 一个简单的Activity无法启动,求助,谢谢
- Android下listview每个Item中包含有按钮,为什么在点击某一行按钮的时候,同时有多行button触发了响应事件?
- app 版本更新
- gulp-connect-proxy和http-proxy-middleware代理
- the rendering target is still loading,Graphical View速度极慢
- bzoj 3876: [Ahoi2014]支线剧情 (有上下界的费用流)
- Android Studio2.0的instant run要求Enable ADB integration,点击后DDMS就被强制断开了