macOS/iOS API解説

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

目次

appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:clockwise:

INDEX>AppKit>NSBezier

パスに円弧を追加します

Objective-C

- (void)appendBezierPathWithArcWithCenter:(NSPoint)center
                                   radius:(CGFloat)radius
                               startAngle:(CGFloat)startAngle
                                 endAngle:(CGFloat)endAngle
                                clockwise:(BOOL)clockwise

Swift

func appendBezierPathWithArcWithCenter(_ center: NSPoint,
                                radius radius: CGFloat,
                            startAngle startAngle: CGFloat,
                              endAngle endAngle: CGFloat,
                             clockwise clockwise: Bool)

解説

パスに円弧を追加します。
円は、centerを中心として、radiusの半径でstartAngleを開始角度(0は右側)から反時計回りにendAngleの終了角度まで描きます
clockwiseがYESなら時計回りに描かれます。
clockwiseがNOなら反時計回りに描かれます。

【clockwise: true】
時計回りに描画されます。
f:id:jjj777:20150304073941p:plain

【clockwise: false】
appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:と同じです。
反時計回りに描画されます。
f:id:jjj777:20150304073722p:plain

返り値

Objective-C

Swift


    
( void )

なし

引数

Objective-C

Swift


    
( NSPoint )center

円弧の中心点

( float )radius

角度

( float )startAngle

開始角度

( float )endAngle

終了角度

( BOOL )clockwise

時計回りYES/NO

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

関連記事(外部サイト)

例文

Objective-C

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

NSBezierPath *thePath = [NSBezierPath bezierPath];

[thePath moveToPoint:NSMakePoint(200,200)];
[thePath lineToPoint:NSMakePoint(200,200)];


[thePath appendBezierPathWithArcWithCenter:NSMakePoint(200,200)
                                radius:100
                                startAngle:0
                                endAngle:90
                                clockwise:YES
                                ];


[[NSColor blueColor] set];

[thePath stroke];

Swift

    //NSBezierPath appendBezierPathWithArcWithCenter:radius:startAngle:endAngle:clockwise
    var aButton015 : NSButton?
    var aView015 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction015(sender : AnyObject?){
        //準備
        let aButton = aButton015
        let aView   = aView015
        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.appendBezierPathWithArcWithCenter(NSMakePoint(100.0, 100.0),
            radius: 50.0,
            startAngle: 0,
            endAngle: 250,
            clockwise: true)
        
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    //実験用ウインドウ作成、実験用ビュー、実行ボタンを作成してウインドウに貼り付けるところまで
    @IBAction func function015(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("viewAction015:")
        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.aButton015 = theButton    //ボタン
        self.aView015 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

更新時バージョン

10.10