Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

visibleFrame

INDEX>AppKit>NSScreen

メニューバーとドックを除いたスクリーン領域を返します

Objective-C

@property(readonly) NSRect visibleFrame

Swift

var visibleFrame: NSRect { get }

解説

メニューバーとドックを除いたスクリーン領域を返します。

設定値

Objective-C

@property(readonly) NSRect visibleFrame

Swift

var visibleFrame: NSRect { get }

表示領域

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.0

参照

更新時のバージョン

OS X 10.10.4
Swift4.0

関連記事(外部サイト)

例文

NSRect sRect = [[NSScreen mainScreen] frame];
NSRect vRect = [[NSScreen mainScreen] visibleFrame];

NSLog([NSString stringWithFormat:@"mainscreen size = x:%.1f,y:%.1f,width:%.1f,height:%.1f",sRect.origin.x,sRect.origin.y,sRect.size.width,sRect.size.height]);
NSLog([NSString stringWithFormat:@"visibleFrame size = x:%.1f,y:%.1f,width:%.1f,height:%.1f",vRect.origin.x,vRect.origin.y,vRect.size.width,vRect.size.height]);

Swift4.0

    //NSScreen deepest
    //NSScreen frame
    //NSScreen visibleFrame
    @IBAction func function003(_ sender: Any) {
        let mainScreen : NSScreen = NSScreen.deepest!
        print("frame = ",mainScreen.frame)
        print("visible frame = ",mainScreen.visibleFrame)
    }

Swift

    //NSScreen mainScreen()
    //NSScreen deepestScreen()
    //NSScreen screens()
    //NSScreen supportedWindowDepths()
    //NSScreen deviceDescription
    //NSScreen visibleFrame
    @IBAction func function001(sender: AnyObject) {
        let theScreen : NSScreen = NSScreen.mainScreen()!
        NSLog("main screen size=  (%.2f✕%.2f)",
                                    Float(theScreen.frame.size.width),
                                    Float(theScreen.frame.size.height) )
        //-> main screen size=  (1366.00✕768.00)
        
        let deepestScreen : NSScreen = NSScreen.deepestScreen()!
        NSLog("deepestScreen screen depth= %d", NSBitsPerPixelFromDepth(deepestScreen.depth) )
        //-> deepestScreen screen depth= 24
        

        
        let supportedWindowDepths : UnsafePointer<NSWindowDepth> = theScreen.supportedWindowDepths
        
        NSLog("supportedWindowDepths = %d", NSBitsPerPixelFromDepth( supportedWindowDepths[0]) )
        //-> supportedWindowDepths = 8
        
        let screenArray : [AnyObject] = NSScreen.screens()!
        for value in screenArray {
            NSLog("screen size=  (%.2f✕%.2f)",
                Float(value.frame.size.width),
                Float(value.frame.size.height) )
        }
        //-> screen size=  (1366.00✕768.00)
        //-> screen size=  (1920.00✕1080.00)

        let descDic : [NSObject:AnyObject] = theScreen.deviceDescription
        NSLog("description = %@", descDic )
        
        //description = {
        //    NSDeviceBitsPerSample = 8;
        //    NSDeviceColorSpaceName = NSCalibratedRGBColorSpace;
        //    NSDeviceIsScreen = YES;
        //    NSDeviceResolution = "NSSize: {72, 72}";
        //    NSDeviceSize = "NSSize: {1366, 768}";
        //    NSScreenNumber = 69680256;
        //}
        
        let visibleFrame : NSRect = theScreen.visibleFrame
        NSLog("visibleFrame = (x=%.2f,y=%.2f,w=%.2f,h=%.2f)",
                                    Float(visibleFrame.origin.x),
                                    Float(visibleFrame.origin.y),
                                    Float(visibleFrame.size.width),
                                    Float(visibleFrame.size.height) )
        visibleFrame
        
        
        var window : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            defer: false,
            screen: theScreen )
        windowArray.addObject(window) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        window.center()//ウインドウをスクリーンの中心に
        window.title = "ウインドウタイトル"//タイトル設定
        window.orderFront(self)//前面に
        window.makeKeyAndOrderFront(self)//表示
    }