macOS/iOS API解説

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

目次

close

INDEX>AppKit>NSDrawer

引き出しが開いていれば閉じます

Objective-C

- (void)close

Swift

func close()

解説

引き出しが開いていれば閉じます。閉じていれば何もしません。

返り値

なし

引数

なし

フレームワーク

ApplicationKit

クラス

NSDrawer

使用可能

10.0

参照

open

更新時のバージョン

OS X 10.10.2

関連記事(外部サイト)

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction1:(id)sender
{
[drawer open];
}

- (IBAction)myAction2:(id)sender
{
[drawer close];
}

@end

Swift

    //NSDrawer close()
    var theDrawer002 : NSDrawer = NSDrawer(contentSize: NSMakeSize(100.0, 100.0),
        preferredEdge: 1 )
    //preferredEdge 1=下、2=右、3=上、4=右
    func buttonAction002(sender: AnyObject){
        
        var theWindow : NSWindow = (sender as NSButton).window!
        //drawerを表示/非表示
        theDrawer002.toggle(theWindow)
    }
    func buttonAction002_close(sender: AnyObject){
        
        var theWindow : NSWindow = (sender as NSButton).window!
        //drawerを表示/非表示
        theDrawer002.close()
    }
    @IBAction func function002(sender: AnyObject) {
        var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false)
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        
        //ボタンを作成
        var theButton1 : NSButton = NSButton(frame: NSMakeRect(50.0, 2.0, 100.0, 30.0))
        theButton1.title = "Toggle"
        theButton1.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton1.action = Selector("buttonAction002:")
        theButton1.target = self
        aWindow.contentView.addSubview(theButton1)
        
        var theButton2 : NSButton = NSButton(frame: NSMakeRect(150.0, 2.0, 100.0, 30.0))
        theButton2.title = "Close"
        theButton2.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton2.action = Selector("buttonAction002_close:")
        theButton2.target = self
        aWindow.contentView.addSubview(theButton2)
        
        let delegateObj : DrawerDelegate = DrawerDelegate()
        delegateObjects.addObject(delegateObj)
        
        theDrawer002.delegate = delegateObj
        
        //テキストフィールドを作成、引き出しに付ける
        var textField : NSTextField = NSTextField(frame: NSMakeRect(10.0, 10.0, 50.0, 30.0))
        theDrawer002.contentView?.addSubview(textField)
        
        theDrawer002.parentWindow = aWindow
        
        //ウインドウの表示
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "ウインドウタイトル"//タイトル設定
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }