在NSView上添加子视图而不会失去焦点(firstResponder status)

时间:2016-02-24 22:45:28

标签: swift cocoa

如何在不丢失firstResponder状态的情况下添加子视图?

    let scrollAreaRect = self.finalFrame
    let scrolledView = NSView(frame: scrollAreaRect)

    // Inserisco pulsanti di esempio
    for i in 1 ... 10{
        let bt = LevelButton(frame: NSRect( x: 0,
                                            y: i*30,
                                            width: Int(scrolledView.frame.width),
                                            height: 30),
                             name: "Primo Livello",
                             number: 1)
        scrolledView.addSubview(bt)
    }

   scrolledView.resignFirstResponder()    
    scrollView = NSScrollView(frame: scrollAreaRect)
    scrollView.resignFirstResponder()

    scrollView.documentView = scrolledView
    scrollView.contentView.scrollToPoint((NSMakePoint(0, scrolledView.frame.size.height)))

    self.addSubview(scrollView)

在初始化函数中运行该代码后,NSView不会调用更多的keyDown句柄。如何将firstResponder状态重新分配给主视图?在所有子视图上调用resignFirstResponder不起作用。

0 个答案:

没有答案