macOS/iOS API解説

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

目次

translateXBy:yBy:

Index>Foundation>NSAffineTransform

座標を平行移動する値をセットします
-(void)translateXBy:(float)deltaX:
        yBy:(float)deltaY:

解説

座標を平行移動する値をセットします。
deltaX X移動量
deltaY Y移動量
(NSAffineTransformクラス、10.3までのAppKitから10.4からFoundationに変更)

返り値

( void )

なし

引数

( float )deltaX

X移動量

( float )deltaY

Y移動量

クラス

NSAffineTransform

Instance Methods

使用可能

10.0

参照

- rotateByDegrees:
- rotateByRadians:
- scaleBy:
- scaleXBy:yBy:

例文

#pragma mark -translateXBy:yBy:
- (IBAction)method007:(id)sender {
    //make bezier path
	NSBezierPath *thePath1 = [NSBezierPath bezierPath];
	
    //make affin transform
    NSAffineTransform *affin = [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:30.0 yBy:50.0];
    [thePath1 transformUsingAffineTransform: affin];
    
    //set color
    [[NSColor redColor] set];
    [thePath1 fill];
    //unlock focus
    [_window.contentView unlockFocus];
    [_window.contentView displayIfNeeded];
}