macOS/iOS API解説

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

目次

transformUsingAffineTransform:

INDEX>AppKit>NSBezier

アフィン変換を使ってパスの変形をします

Objective-C

- (void)transformUsingAffineTransform:(NSAffineTransform *)aTransform

Swift

func transformUsingAffineTransform(_ aTransform: NSAffineTransform)

解説

アフィン変換(aTransform)を使ってレシーバーにおいて全ての点を変換します

f:id:jjj777:20150314215324p:plain

返り値

なし

引数

アフィン変換
Objective-C

- (void)transformUsingAffineTransform:(NSAffineTransform *)aTransform

Swift

func transformUsingAffineTransform(_ aTransform: NSAffineTransform)

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

関連記事(外部サイト)

例文

Objective-C

#import "MyView.h"

@implementation MyView

//NSViewのサブクラス MyViewのDrawRectに上書き
-(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 translateXBy: 10.0 yBy: 10.0];
[thePath1 transformUsingAffineTransform: affin];

[[NSColor redColor] set];
[thePath1 fill];





}

@end

Swift

    //NSBezierPath
    var aButton042 : NSButton?
    var aView042 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction042(sender : AnyObject?){
        //準備
        let aButton = aButton042
        let aView   = aView042
        var theWindow : NSWindow = aButton!.window!
        //準備ここまで
        
        //ビューにフォーカスを当てる
        aView?.lockFocus()
        //バックグラウンドカラーを描画
        let backgroundColor = NSColor.whiteColor()
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        
        NSColor.redColor().setStroke()
        NSColor.magentaColor().setFill()
        //空のベジェパスを作成
        let aBezier : NSBezierPath = NSBezierPath()
        aBezier.moveToPoint(CGPoint(x: 176.95,y: 44.90))
        aBezier.curveToPoint(CGPoint(x: 166.71,y: 145.89),
            controlPoint1: CGPoint(x: 76.63,y: 76.78),
            controlPoint2: CGPoint(x: 82.59,y: 206.70))
        aBezier.curveToPoint(CGPoint(x: 176.95,y: 44.90),
            controlPoint1: CGPoint(x: 237.55,y: 224.76),
            controlPoint2: CGPoint(x: 276.83,y: 95.98))
        aBezier.closePath()
        
        var affine : NSAffineTransform = NSAffineTransform()
        affine.scaleXBy(1.0, yBy: 0.5)
        aBezier.transformUsingAffineTransform(affine)

        
        aBezier.fill()
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    //実験用ウインドウ作成、実験用ビュー、実行ボタンを作成してウインドウに貼り付けるところまで
    @IBAction func function042(sender: AnyObject) {
        var aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "NSBezierPath"//タイトル設定
        //ボタン
        var theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 0.0, 100.0, 30.0))
        theButton.title = "Action"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("viewAction042:")
        theButton.target = self
        
        aWindow.contentView.addSubview(theButton)
        //ビュー
        var theView : NSView = NSView(frame: NSMakeRect(0.0, 20.0, 300.0, 100.0))
        //レイヤーバックドにするのだ
        theView.wantsLayer = true
        aWindow.contentView.addSubview(theView)
        
        //実験ウインドウにUIパーツを渡す
        self.aButton042 = theButton    //ボタン
        self.aView042 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

更新時バージョン

10.10