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