initWithTransform:
Index>Foundation>NSAffineTransform
変換マトリックスをaTransformで初期化して返します
-(id)initWithTransform:(NSAffineTransform *)aTransform:
解説
変換マトリックスをaTransformで初期化して返します。(NSAffineTransformクラス、10.3までのAppKitから10.4からFoundationに変更)
返り値
( id )
変換マトリックス
引数
( NSAffineTransform * )aTransform
変換マトリックス
フレームワーク
Foundation
クラス
NSAffineTransform
Instance Methods
使用可能
10.0
参照
例文
drawRect:で使わない場合
- (IBAction)method002:(id)sender { //make bezier path NSBezierPath *thePath1 = [NSBezierPath bezierPath]; //make affin transform NSAffineTransform *affin = [NSAffineTransform transform]; //NSAffineTransform *affin2 = [[NSAffineTransform alloc] initWithTransform:affin]; //focus window's view [_window.contentView lockFocus]; NSRect rect = [_window.contentView frame ]; [[NSColor windowBackgroundColor] set]; NSRectFill(rect); //set winding rule [thePath1 setWindingRule:NSEvenOddWindingRule]; [thePath1 moveToPoint:NSMakePoint(20,20)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(50,50,100,100)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(20,20,80,80)]; //1st draw [[NSColor blueColor] set]; [thePath1 fill]; [affin translateXBy: 50.0 yBy: 0.0]; NSAffineTransform *affin2 = [[NSAffineTransform alloc] initWithTransform:affin]; [thePath1 transformUsingAffineTransform: affin]; //2nd draw [[NSColor yellowColor] set]; [thePath1 fill]; [affin2 translateXBy: 0.0 yBy: 50.0]; [thePath1 transformUsingAffineTransform: affin2]; //3rd draw [[NSColor redColor] set]; [thePath1 fill]; //unlock focus [_window.contentView unlockFocus]; [_window.contentView displayIfNeeded]; }
drawRect:で使う場合
#import "MyView.h" @implementation MyView -(void)drawRect:(NSRect)rect { NSBezierPath *thePath1 = [NSBezierPath bezierPath]; NSAffineTransform *affin = [NSAffineTransform transform]; NSAffineTransform *affin2 = [NSAffineTransform transform]; [thePath1 setWindingRule:NSEvenOddWindingRule]; [thePath1 moveToPoint:NSMakePoint(20,20)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(50,50,100,100)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(20,20,80,80)]; [[NSColor blueColor] set]; [thePath1 fill]; [affin translateXBy: 10.0 yBy: 0.0]; [affin2 translateXBy: 0.0 yBy: 10.0]; [thePath1 transformUsingAffineTransform: affin]; [[NSColor yellowColor] set]; [thePath1 fill]; [affin initWithTransform:affin2]; [thePath1 transformUsingAffineTransform: affin]; [[NSColor redColor] set]; [thePath1 fill]; } @end