macOS/iOS API解説

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

目次

appendBezierPath:

INDEX>AppKit>NSBezier

レシーバーのパスに別のベジエパスを追加します

Objective-C

- (void)appendBezierPath:(NSBezierPath *)aPath

Swift

func appendBezierPath(_ aPath: NSBezierPath)

解説

レシーバーのパスに別のベジエパス(aPath)を追加します。
いままでのパスと接続するわけではありません。

これに
f:id:jjj777:20150301174533p:plain

これを加えると

let rBezier : NSBezierPath =
        NSBezierPath(ovalInRect: NSMakeRect(100.0, 100.0, 50.0, 50.0))
aBezier.appendBezierPath(rBezier)

こうなる
f:id:jjj777:20150302210947p:plain

返り値

なし

引数

Objective-C

(NSBezierPath *)aPath

Swift

aPath: NSBezierPath

付け加えるパス

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

関連記事(外部サイト)

例文

Objective-C

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

NSBezierPath *thePath = [NSBezierPath bezierPath];

[thePath moveToPoint:NSMakePoint(20,20)];
[thePath lineToPoint:NSMakePoint(120,120)];

[thePath appendBezierPath:[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(50,50,150,100)]];
[[NSColor redColor] set];

[thePath stroke];


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

NSBezierPath *thePath = [NSBezierPath bezierPath];

[thePath moveToPoint:NSMakePoint(20,20)];
[thePath lineToPoint:NSMakePoint(120,120)];

[thePath appendBezierPath:[NSBezierPath bezierPathWithRect:NSMakeRect(50,50,150,100)]];

[thePath appendBezierPath:[NSBezierPath bezierPathWithRect:NSMakeRect(130,130,150,100)]];

[[NSColor redColor] set];

[thePath stroke];


}

Swift

    //NSBezierPath appendBezierPath
    var aButton010 : NSButton?
    var aView010 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction010(sender : AnyObject?){
        //準備
        let aButton = aButton010
        let aView   = aView010
        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 rBezier : NSBezierPath =
        NSBezierPath(ovalInRect: NSMakeRect(100.0, 100.0, 50.0, 50.0))
        
        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()
        //ここ
        aBezier.appendBezierPath(rBezier)
        
        aBezier.fill()
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }

更新時バージョン

10.10