macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

transform

変換マトリックスを作って返します

Index>Foundation>NSAffineTransform

解説

変換マトリックスを作って返します。
(NSAffineTransformクラス、10.3までAppKitにあったが10.4からFoundationに変更)

返り値

( NSAffineTransform * )

変換マトリックス

引数

クラス

NSAffineTransform

Class Methods

使用可能

10.0

参照

例文

drawRectに書かないやり方。ビューをlockFocusする。

- (IBAction)method001:(id)sender {
    //make bezier path
	NSBezierPath *thePath1 = [NSBezierPath bezierPath];
	
    //make affin transform
    NSAffineTransform *affin = [NSAffineTransform transform];
	NSAffineTransform *affin2 = [NSAffineTransform transform];
    
    //focus window's view
    [_window.contentView lockFocus];
        //clear window
        NSRect rect = [_window.contentView frame ];
        [[NSColor windowBackgroundColor] set];
        NSRectFill(rect);
        //set winding rule
        [thePath1 setWindingRule:NSEvenOddWindingRule];
        //move pen
        [thePath1 moveToPoint:NSMakePoint(20,20)];
        //make path
        [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(50,50,100,100)];
        [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(20,20,80,80)];
        //set color
        [[NSColor blueColor] set];
        
        //fill path
        [thePath1 fill];
        
        //set transform
        [affin translateXBy: 10.0 yBy: 10.0];
        [affin2 translateXBy: 10.0 yBy: 10.0];
        [affin appendTransform:affin2];
        [thePath1 transformUsingAffineTransform: affin];
        
        //set color
        [[NSColor redColor] set];
        [thePath1 fill];
    //unlock focus
    [_window.contentView unlockFocus];
    [_window.contentView displayIfNeeded];
}