親愛なるココアプログラマーの皆様へ
私が達成したいこと:
キャンバスにチェックボックス、popUpButton (非表示)、および NSView があります。myCheckbox がチェックされている場合 -> popUpButton を表示し、NSView で bezierPath を介して線を引きます。myCheckbox がチェックされていない場合 -> popUpButton を再度非表示にし、パスを「描画解除」します
コード:
- (IBAction)isChecked:(id)sender {
//if myChekcbox is checked, show the pop up button
if ([sender state]==NSOnState) {
NSLog(@"Checked");
[myPopUp setHidden:NO];
}
else
{
//if the checkbox is unchecked, hide the popupbutton
[myPopUp setHidden:YES];
NSLog(@"Unchecked");
}
//reload my drawrect method (reload the view)
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)dirtyRect
{
//if the checkedbutton is checked, draw the line
if ([myCheckbox state]==NSOnState)
{
NSBezierPath *myPath = [NSBezierPath bezierPath];
[myPath moveToPoint:NSMakePoint(10, 20)];
[myPath lineToPoint:NSMakePoint(50, 20)];
[myPath setLineWidth:2];
[myPath stroke];
}
}
問題:
if checked state = NSOnState popUpButton は表示されますが、線が描画されず、なぜだろうか...個人的には接続の問題だと思います。
ここにプロジェクト ファイルをアップロードしました (かなり小さい 35 KB です): Drawing.zip
グローバル に: NSView のドキュメントを読みましたが、ビューに描画する方法は 1 つしかなく、drawRect メソッドを使用する方法であると書かれています。これは実際に本当ですか?また、これはビューに描画する降下方法ですか? (ビュー内の関数とメソッド内の setNeedsDisplay:YES の場合)
前もって感謝します、ベン