Reputation: 11
I am attempting to learn the basics of quartz and do not understand why this will not work - this should move the red rectangle to the right when the button is pushed, bat at the momoent, it does not do anything - the "NSLog(A"help"); was to try to figure out if the button was functioning - thanks
@implementation QuartzView
-(IBAction)moveRight:(id)sender{
NSLog(@"Help");
lR += 50;
}
- (id)initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame:frameRect];
if (self) {
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect
{
CGContextRef myContext = [[NSGraphicsContext // 1
currentContext] graphicsPort];
// Drawing code here.
CGContextSetRGBFillColor (myContext, 1, 0, 0, 1);// 3
CGContextFillRect (myContext, CGRectMake (lR, 0, 200, 100 ));
[self setNeedsDisplay:YES];
}
@end
Thanks!
Upvotes: 1
Views: 149
Reputation: 54630
Try [self setNeedsDisplay]
inside moveRight after you increment lR.
Upvotes: 0
Reputation: 2080
You don't want to call setNeedsDisplay in drawRect; that simply says, "now that I've drawn the view, make me do it again!"
You want to call setNeedsDisplay in your action, to update the screen after you moves the rectangle.
Upvotes: 1