canRepresent
スクリーンでサポートされる色深度を返します
Swift
open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool
解説
ガモットマッピング可能かどうかを返します。
返り値
色深度の配列
Swiftopen func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool
引数
フレームワーク
ApplicationKit
クラス
NSScreen
使用可能
10.12
参照
更新時のバージョン
OS X 10.14.5
Swift4.0
例文
Swift4.0
@IBAction func function008(_ sender: Any) { let screenArray : [AnyObject] = NSScreen.screens for value in screenArray { let result : Bool = value.canRepresent(.sRGB) if (result){ print("YES") }else{ print("NO") } } }
name
解説
アピアランスの名前(読み込みのみ)
フレームワーク
ApplicationKit
クラス
NSAppearance
使用可能
10.9-
更新時のバージョン
OS X 10.11
参照
関連記事
例文
//NSAppearance initWithAppearanceNamed:bundle: //http://cocoaapi.hatenablog.com/entry/Appkit/NSAppearance/initWithAppearanceNamed_bundle_ //NSAppearance name // @IBAction func function001( sender: AnyObject) { //アピアランスの変更 let ap : NSAppearance = NSAppearance(named: NSAppearanceNameVibrantDark)! NSLog("name = %@",ap.name) //->name = NSAppearanceNameVibrantDark let 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.appearance = ap aWindow.center()//ウインドウをスクリーンの中心に aWindow.title = "ウインドウタイトル"//タイトル設定 // let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0)) theButton.title = "Change" theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton.action = Selector("buttonAction001:") theButton.target = self theButton.setButtonType(.MomentaryLightButton) //.SwitchButton //.PushOnPushOffButton aWindow.contentView!.addSubview(theButton) aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }
initWithAppearanceNamed:bundle:
バンドルと名前でNSAppearanceオブジェクトのインスタンスを初期化して返します
- (instancetype)initWithAppearanceNamed:(NSString *)name
bundle:(NSBundle *)bundle
init?(appearanceNamed name: String, bundle bundle: NSBundle?)
引数
【name】
アピアランスファイル名
Objective-C
(NSString *)name
name: String,
【bundle】
アピアランスファイルが含まれるバンドル
Objective-C
(NSBundle *)bundle
bundle: NSBundle?
フレームワーク
ApplicationKit
クラス
NSAppearance
使用可能
10.9-
更新時のバージョン
OS X 10.11
参照
関連記事
例文
//NSAppearance initWithAppearanceNamed:bundle: //http://cocoaapi.hatenablog.com/entry/Appkit/NSAppearance/initWithAppearanceNamed_bundle_ @IBAction func function001( sender: AnyObject) { //アピアランスの変更 let ap : NSAppearance = NSAppearance(named: NSAppearanceNameVibrantDark)! let 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.appearance = ap aWindow.center()//ウインドウをスクリーンの中心に aWindow.title = "ウインドウタイトル"//タイトル設定 // let theButton : NSButton = NSButton(frame: NSMakeRect(50.0, 50.0, 100.0, 30.0)) theButton.title = "Change" theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle theButton.action = Selector("buttonAction001:") theButton.target = self theButton.setButtonType(.MomentaryLightButton) //.SwitchButton //.PushOnPushOffButton aWindow.contentView!.addSubview(theButton) aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }
takeIntegerValueFrom:
NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification
NSWorkspaceDidTerminateApplicationNotification
アプリケーションが終了するときにポストされる
解説
アプリケーションが終了するときにポストされる
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.0
更新時のバージョン
OS X 10.10.3
Swift1.2
参照
関連記事(外部サイト)
例文
//NSWorkspace NSWorkspaceDidTerminateApplicationNotification //アプリケーションが終了しようとするとき var switch049 : Bool = false func notifyNSWorkspaceDidTerminateApplicationNotification(notify:NSNotification) { //NSLog("%@",notify.description) let bundleID : String = (notify.userInfo! as Dictionary)["NSApplicationBundleIdentifier"]! as! String NSLog("Bundle ID = %@",bundleID) // -> Bundle ID = com.apple.mail let appName : String = (notify.userInfo! as Dictionary)["NSApplicationName"]! as! String NSLog("application name = %@",appName) // -> application name = メール let appPathe : String = (notify.userInfo! as Dictionary)["NSApplicationPath"]! as! String NSLog("application path = %@",appPathe) // -> application path = /Applications/Mail.app let appProcessID : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessIdentifier"]! as! NSNumber NSLog("process id = %d",appProcessID.integerValue) // -> process id = 36580 let appProcessSerialNumberHigh : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberHigh"]! as! NSNumber NSLog("process serial number high = %d",appProcessSerialNumberHigh.integerValue) // ->process serial number high = 0 let appProcessSerialNumberLow : NSNumber = (notify.userInfo! as Dictionary)["NSApplicationProcessSerialNumberLow"]! as! NSNumber NSLog("process serial number low = %d",appProcessSerialNumberLow.integerValue) // ->process serial number low = 5145832 let runningApp : NSRunningApplication = (notify.userInfo! as Dictionary)["NSWorkspaceApplicationKey"]! as! NSRunningApplication NSLog("runningApp = %@",runningApp.description) // ->runningApp = <NSRunningApplication: 0x600000105340 (com.apple.mail - 36867)> NSLog("runningApp = %@",runningApp.launchDate!.description) // ->runningApp = 2015-04-29 09:18:27 +0000 let exitStatus : NSNumber = (notify.userInfo! as Dictionary)["NSWorkspaceExitStatusKey"]! as! NSNumber NSLog("exit status = %d",appProcessSerialNumberHigh.integerValue) // ->exit status = = 0 }
convertRectToBacking:
デバイスピクセルとディスプレイの座標システムとの変換
- (NSRect)convertRectToBacking:(NSRect)aRectSwift
func convertRectToBacking(_ aRect: NSRect) -> NSRect
返り値
NSRect
Swift
NSRect
引数
(NSRect)aRect
Swift
(_ rect: NSRect)
フレームワーク
ApplicationKit
クラス
NSScreen
使用可能
10.7-
更新時のバージョン
OS X 10.14.5
SWIFT4.0
参照
関連記事(外部サイト)
例文
Swift4.0
@IBAction func function010(_ sender: Any) { let screenArray : [NSScreen] = NSScreen.screens for value in screenArray { let rect : NSRect = value.convertRectToBacking(NSMakeRect(0.0, 0.0,100.0, 100.0)) print("rect = (\(rect.origin.x) ,\(rect.origin.y)(\(rect.size.width),\(rect.size.height)))") } //rect = (0.0 ,0.0(100.0,100.0)) //<- Normal Display //rect = (0.0 ,0.0(200.0,200.0)) //<- MacBooK retina Display //rect = (0.0 ,0.0(100.0,100.0)) //<- Normal Display }
Swift//NSScreen convertRectToBacking @IBAction func function006(sender: AnyObject) { let theScreen : NSScreen = NSScreen.mainScreen()! let newRect : NSRect = theScreen.convertRectToBacking(NSMakeRect(0.3, 0.0, 100.3, 123.5)) NSLog("newRect = (x=%.2f,y=%.2f,w=%.2f,h=%.2f)", Float(newRect.origin.x), Float(newRect.origin.y), Float(newRect.size.width), Float(newRect.size.height) ) //通常ディスプレイの場合(倍率1.0) -> newRect = (x=0.30,y=0.00,w=100.30,h=123.50) }