lockFocusIfCanDraw
ビューに描画できるかを確認してからフォーカスをロックします
解説
ビューに描画できるかを確認してからフォーカスをロックします。
返り値
( BOOL )
YES/NO
引数
フレームワーク
ApplicationKit
クラス
NSView
Instance Methods
使用可能
10.0
参照
例文
#import "SetImage.h" @implementation SetImage - (IBAction)set:(id)sender { //開けるファイル拡張子の配列 NSArray *imgTypes = [ NSArray arrayWithObjects : @"tiff",@"pdf",nil ]; //OpenPanelを作る NSOpenPanel *opImage = [ NSOpenPanel openPanel ]; //Imageを作る NSImage *img; NSImage *img2; //OpenPanelの結果のボタン番号 int opRet; //OpenPanelでファイル選択 opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Pictures" //どのどのファイルを選択しておくか types : imgTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら //NSImageを作ってファイルから読み込む img = [ [ NSImage alloc ] initWithContentsOfFile: [ opImage filename ] ]; //NSImageをバンドルファイルからつくる img2 = [NSImage imageNamed: @"NSApplicationIcon" ]; //imgを描画対象にする [img lockFocus]; //描画対象にimg2を合成する [img2 compositeToPoint:NSMakePoint(10,100) operation:NSCompositeXOR]; //合成後のimgをImageViewに表示する [image setImage:img]; //imgを描画から外す [img unlockFocus]; if ([sender lockFocusIfCanDraw]) { NSLog(@"YES"); [sender setImage:img]; }else{ NSLog(@"NO"); } [sender unlockFocus]; } } @end