0

をドラッグしようとしていますがCGRect、何も起こりません。四角形は同じ場所にとどまります。これが私のmouseDragged:コードです:

-(void)mouseDragged:(NSEvent *)theEvent{

NSPoint eventLocation = [theEvent locationInWindow];
NSPoint location = [self convertPoint:eventLocation fromView:self];

int locationX = location.x;
int locationY = location.y;

[self setNeedsDisplay:TRUE];

if(CGRectContainsPoint(myRect, location)){

myRect.origin.x = locationX;
myRect.origin.y = locationY;
}
}

このコードはNSView. myRect私は四角形を描きdrawRectます:

これが私の drawRect です:

- (void)drawRect:(NSRect)rect
{

int width = self.bounds.size.width;
int height = self.bounds.size.height;

myRect = CGRectMake((width/2)-50, (height /2)-50, 100, 100);


CGContextRef myContext = [[NSGraphicsContext currentContext] graphicsPort];
CGContextSetRGBFillColor(myContext, 1, 0, 0, 1);
CGContextFillRect(myContext, myRect);

 NSLog(@"drawRect: called");

}

何か案は?

4

1 に答える 1