0
我的問題:填充正方形的顏色從黑到全藍(255),沒有過渡顏色(最深的藍色,深藍色,藍色...)。看起來CGContextSetRGBStroke是可加的(WTF Oo)。就好像藍色是14,下一次更新我把140藍色將是154,而不是我設定的140。CGContextSetRGBFillColor沒有設置好顏色
有人得到這個問題嗎?
在.M的.HCGFloat angle;
int width;
int height;
NSTimer* timer;
CGPoint touch;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
angle=0;
width = frame.size.width;
height= frame.size.height;
//self.backgroundColor=[UIColor colorWithRed:0.1 green:0.1 blue:1 alpha:1];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(update:) userInfo:nil repeats:YES];
}
return self;
}
-(void)update:(NSTimer*)theTimer
{
[self setNeedsDisplay];
}
NS_INLINE CGFloat radians(CGFloat ang)
{
return ang*(M_PI/180.0f);
}
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx=UIGraphicsGetCurrentContext();
//CGContextSetRGBFillColor(ctx, -1,-1,-1,-1);
CGContextSaveGState(ctx);
CGRect ourRect = CGRectMake(40+angle, 40+angle, 240, 120);
CGFloat colour=(touch.y/768)*255;
NSQLog(@"draw %f",colour);
CGContextSetRGBFillColor(ctx, 0.0,0.0,colour,1);
CGContextClearRect(ctx, rect);
CGContextFillRect(ctx, ourRect);
CGContextSetRGBStrokeColor(ctx, 0.0, 1.0, 0.0, 1.0);
CGContextStrokeRectWithWidth(ctx, ourRect, 10);
CGContextRestoreGState(ctx);
angle+=1;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
touch= [[touches anyObject] locationInView:self];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
touch= [[touches anyObject] locationInView:self];
}
TRUE !!!我正在使用Processing來測試圖形代碼,並忘記將0-255範圍顏色更改爲0-1範圍。 Thks ... 1天找到它...真誠thk – xeonarno 2010-09-30 16:33:33
如果我的文章有幫助,請注意將其標記爲接受的答案? – 2010-09-30 17:10:12