macOS/iOS API解説

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

目次

appendBezierPathWithArcFromPoint:toPoint:radius:

INDEX>AppKit>NSBezier

パスに円弧を追加します

Objective-C

- (void)appendBezierPathWithArcFromPoint:(NSPoint)fromPoint
                                 toPoint:(NSPoint)toPoint
                                  radius:(CGFloat)radius

Swift

func appendBezierPathWithArcFromPoint(_ fromPoint: NSPoint,
                              toPoint toPoint: NSPoint,
                               radius radius: CGFloat)

解説

円弧を追加します。開始点(fromPoint)から半径(radius)で終了点(toPoint)までの円弧を追加します。

f:id:jjj777:20150303234731p:plain

f:id:jjj777:20150303234854p:plain

返り値

Objective-C

Swift


    
( void )

なし

引数

Objective-C

Swift


    
( NSPoint )fromPoint

追加する円弧の開始点

( NSPoint )toPoint

終了点

( float )radius

半径(ピクセル)

フレームワーク

ApplicationKit

クラス

NSBezierPath

使用可能

10.0

参照

関連記事(外部サイト)

例文

Objective-C

#import "MyView.h"

@implementation MyView

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

NSBezierPath *thePath = [NSBezierPath bezierPath];

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


[thePath appendBezierPathWithArcFromPoint:NSMakePoint(250,250) toPoint:NSMakePoint(0,250) radius:100];

[[NSColor blueColor] set];

[thePath stroke];


}

@end

Swift

    //NSBezierPath appendBezierPathWithArcFromPoint
    var aButton013 : NSButton?
    var aView013 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction013(sender : AnyObject?){
        //準備
        let aButton = aButton013
        let aView   = aView013
        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 aRect : NSRect =  NSMakeRect(100.0, 100.0,100.0,60.0)
        let topMid : NSPoint = NSMakePoint(NSMidX(aRect), NSMaxY(aRect))
        let topLeft : NSPoint = NSMakePoint(NSMinX(aRect), NSMaxY(aRect))
        let topRight : NSPoint = NSMakePoint(NSMaxX(aRect), NSMaxY(aRect))
        let bottomRight : NSPoint = NSMakePoint(NSMaxX(aRect), NSMinY(aRect))
        let radius : CGFloat = 10.0
        let aBezier : NSBezierPath = NSBezierPath()
        aBezier.moveToPoint(topMid)
        aBezier.appendBezierPathWithArcFromPoint(topLeft, toPoint: aRect.origin, radius: radius)
        aBezier.appendBezierPathWithArcFromPoint(aRect.origin, toPoint: bottomRight, radius: radius)
        aBezier.appendBezierPathWithArcFromPoint(bottomRight, toPoint: topRight , radius: radius)
        aBezier.appendBezierPathWithArcFromPoint(topRight, toPoint: topLeft , radius: radius)
        aBezier.closePath()
        aBezier.fill()
        aBezier.lineWidth = 2.0
        aBezier.stroke()
        
        //ビューからフォーカスを外す
        aView?.unlockFocus()
        NSLog("!!! %@",aBezier.description)
    }
    //実験用ウインドウ作成、実験用ビュー、実行ボタンを作成してウインドウに貼り付けるところまで
    @IBAction func function013(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("viewAction013:")
        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.aButton013 = theButton    //ボタン
        self.aView013 = theView        //テストビュー
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

更新時バージョン

10.10