rotateByRadians:
Index>Foundation>NSAffineTransform
変換マトリックスの回転角度をラジアンでセットします
-(void)rotateByRadians:(float)angle:
解説
変換マトリックスの回転角度をラジアンでセットします。
角度は反時計回りに増えていきます。
(NSAffineTransformクラス、10.3までのAppKitから10.4からFoundationに変更)
ラジアンはdegrees*PI/180
//PIを3.14...と定義
#define PI 3.14159265358979323846 //関数定義degrees*PI/180がradians static inline double radians(double degrees) { return degrees * PI / 180; }
返り値
( void )
なし
フレームワーク
Foundation
クラス
NSAffineTransform
Instance Methods
使用可能
10.0
参照
- rotateByDegrees
- scaleBy:
- scaleXBy:yBy:
- translateXBy:yBy:
例文
#pragma mark -rotateByDegrees: - (IBAction)method004:(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]; [thePath1 moveToPoint:NSMakePoint(20,20)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(50,50,100,100)]; [thePath1 appendBezierPathWithOvalInRect:NSMakeRect(20,20,80,80)]; //1st drawing [[NSColor blueColor] set]; [thePath1 fill]; //already define inline function. //#define PI 3.14159265358979323846 //static inline double radians(double degrees) { return degrees * PI / 180; } //add rotate transform [affin rotateByRadians:radians(-30.0)]; [thePath1 transformUsingAffineTransform: affin]; //2nd drawing [[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]; [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 rotateByRadians:0.3]; [thePath1 transformUsingAffineTransform: affin]; [[NSColor redColor] set]; [thePath1 fill]; } @end