macOS/iOS API解説

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

目次

relativeMoveToPoint:

INDEX>AppKit>NSBezier

現在の位置からaPoint分ペン位置を移動します

Objective-C

-(void)relativeMoveToPoint:(NSPoint)aPoint:

Swift


解説

現在の位置からaPoint分ペン位置を移動します。
線は引きません。

f:id:jjj777:20150302073046p:plain

返り値

Objective-C

Swift

( void )

なし

引数

Objective-C

Swift

( NSPoint )aPoint

動かし終わる量

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照


closePath - Cocoa API解説(iOS/OS X)


moveToPoint: - Cocoa API解説(iOS/OS X)


relativeLineToPoint: - Cocoa API解説(iOS/OS X)


relativeCurveToPoint:controlPoint1:controlPoint2: - Cocoa API解説(iOS/OS X)

関連記事(外部サイト)

例文

Objective-C

//NSViewのサブクラス MyViewのDrawRectに上書き
-(void)drawRect:(NSRect)rect
{

NSBezierPath *thePath = [NSBezierPath bezierPath];

[NSBezierPath setDefaultLineCapStyle:NSRoundLineCapStyle];

[thePath moveToPoint:NSMakePoint(20,20)];
[thePath curveToPoint:NSMakePoint(120,120)
            controlPoint1:NSMakePoint(100,200)
            controlPoint2:NSMakePoint(120,120)
            ];


[thePath relativeMoveToPoint:NSMakePoint(10,0)];
[thePath lineToPoint:NSMakePoint(20,20)];

[thePath setLineWidth:5];
[[NSColor redColor] set];

[thePath stroke];


}

Swift

    //NSBezierPath
    var aButton009 : NSButton?
    var aView009 : NSView?
    //実験用ウインドウのボタンを押した時に実行されるところ
    func viewAction009(sender : AnyObject?){
        //準備
        let aButton = aButton009
        let aView   = aView009
        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: 125.00,y: 45.00))
        //線を引く
        aBezier.lineToPoint(CGPoint(x: 185.00,y: 49.00))
        aBezier.lineToPoint(CGPoint(x: 230.00,y: 123.00))
        //現在位置からの移動
        aBezier.relativeMoveToPoint(NSMakePoint(0.00, 20.00))
        aBezier.relativeLineToPoint(NSMakePoint(-50.00, 10.00))
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    @IBAction func function009(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("viewAction009:")
        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.aButton009 = theButton    //ボタン
        self.aView009 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示

    }

更新時のバージョン

OS X 10.10