macOS/iOS API解説

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

目次

contentRectForFrameRect:

INDEX>AppKit> NSWindow

ウインドウの内容矩形のスクリーン座標とサイズを返します

Objective-C

-(NSRect)contentRectForFrameRect:(NSRect )frameRect:

Swift


解説

ウインドウの内容矩形のスクリーン座標とサイズを返します。
frameRectと返される値はスクリーン座標。

f:id:jjj777:20150301133449p:plain

返り値

Objective-C

Swift

( NSRect )

ウインドウの内容矩形

引数

( NSRect  )frameRect

フレームワーク

ApplicationKit

クラス

NSWindow

使用可能

10.3

参照

-frameRectForContentRect:

  1. contentRectForFrameRect:styleMask:

+contentRectForFrameRect:styleMask:

例文

NSRect contentRect;

contentRect = [[sender window] contentRectForFrameRect:NSMakeRect(0.0,0.0,300.0,300.0) ];
NSLog([NSString stringWithFormat:@"%.1f,%.1f,%.1f,%.1f",contentRect.origin.x,contentRect.origin.y,contentRect.size.width,contentRect.size.height]);

Swift

    //NSWindow contentRectForFrameRect
    @IBAction func function038(sender: AnyObject) {
        var windowRect : NSRect = NSMakeRect(100.0, 0.0, 300.0, 200.0)
        NSLog("windowRect %.2f,%.2f,%.2f,%.2f",
            Float(windowRect.origin.x),
            Float(windowRect.origin.y),
            Float(windowRect.size.width),
            Float(windowRect.size.height))
        //->100.00,0.00,300.00,200.00
        var aWindow : NSWindow = NSWindow(contentRect: windowRect, styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false)
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.setDynamicDepthLimit(true )
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
        var contentRect : NSRect = aWindow.contentRectForFrameRect(windowRect)
        NSLog("contentRect %.2f,%.2f,%.2f,%.2f",
            Float(contentRect.origin.x),
            Float(contentRect.origin.y),
            Float(contentRect.size.width),
            Float(contentRect.size.height))
        //->100.00,0.00,300.00,178.00
    }