1
내 문제는 UpdateRect가 drawRect 메서드를 호출 할 때 rect가 높이를 업데이트하지 않는다는 것입니다.문제 NSRect 그리기
버튼을 클릭하면 렉 높이가 20으로 표시되지만 10으로 유지됩니다. 이유는 무엇입니까?
@implementation Graphic_view
int height = 10; //The height of my rect.
-(IBAction)updateRect:(id)sender {
height += 10;
//Calling the drawrect method
[self performSelector:@selector(drawRect:)];
}
-(void)drawRect:(NSRect)dirtyRect {
NSLog(@"DrawRect has been called !");
// Drawing code here.
NSRect viewBounds = [self bounds];
NSColor *color = [NSColor orangeColor];
[colore set];
NSRectFill(viewBounds);
NSRect myRect;
myRect.origin.x = 20;
myRect.origin.y = 20;
myRect.size.height = height;
myRect.size.width = 100;
NSColor *whiteColor = [NSColor whiteColor];
[whiteColor set];
NSRectFill(myRect);
}
@end
오! 고맙습니다 ! 하지만 내 코드를 가져 와서 "[self setNeedsDisplay : YES]; ? 나는 그것을 틀린 장소에 두는 것을 걱정한다) – Alberto
어서, 지금. 게으르지 말자. 알베르토. 더 좋은 방법은 당신이 빠뜨린 근본적인 코코아 그림 개념이 있다는 것을 알고 있기 때문에 관련 문서를 읽는 것입니다. ** 당신이 ** 정말로 읽을 필요가있는 가이드가 있습니다 ** : http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaDrawingGuide/Introduction/Introduction.html –
해결했습니다! 고맙습니다 ! – Alberto