macOS/iOS API解説

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

目次

frame

INDEX>AppKit> NSWindow

ウインドウのフレーム矩形をスクリーン座標で返します

Objective-C

@property(readonly) NSRect frame

Swift

var frame: NSRect { get }

解説

ウインドウのフレーム矩形をスクリーン座標で返します。

f:id:jjj777:20150318222220p:plain

返り値

( NSRect )

ウインドウのフレーム矩形

引数

フレームワーク

ApplicationKit

クラス

NSWindow

使用可能

10.0

参照

- screen
- deepestScreen

関連記事(外部サイト)

更新時バージョン

10.10

例文

Objective-C

#import "Controller.h"

@implementation Controller

- (IBAction)pushButton:(id)sender
{
NSRect contentRect;

contentRect = [myWindow frame];

[info setStringValue:[NSString stringWithFormat:@"%.1f,%.1f,%.1f,%.1f",contentRect.origin.x,contentRect.origin.y,contentRect.size.width,contentRect.size.height]];

}
@end

Swift

    //NSWindow  frame
    @IBAction func function051(sender: AnyObject) {
        var theWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false)
        windowArray.addObject(theWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        theWindow.center()//ウインドウをスクリーンの中心に
        theWindow.title = "ウインドウタイトル"//タイトル設定
        theWindow.orderFront(self)//前面に
        theWindow.makeKeyAndOrderFront(self)//表示
        
        NSLog("x = %.2f,y = %.2f,w = %.2f,h = %.2f", Float(theWindow.frame.origin.x ),
                            Float(theWindow.frame.origin.y),
                            Float(theWindow.frame.size.width),
                            Float(theWindow.frame.size.height))
    }