IBDesignable视图无法渲染 [英] IBDesignable view not rendering

查看:253
本文介绍了IBDesignable视图无法渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 @IBDesignable 视图,我已将其指定为macOS storyboard中场景的基类。例如,在Xcode 8中,Swift 3:

I have a simple @IBDesignable view that I have specified as the base class for a scene in my macOS storyboard. E.g., in Xcode 8, Swift 3:

@IBDesignable class OvalView: NSView {

    @IBInspectable var strokeColor: NSColor = .black { didSet { needsDisplay = true } }

    @IBInspectable var brushSize: CGFloat = 5.0 { didSet { needsDisplay = true } }

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        strokeColor.setStroke()

        let path = NSBezierPath(ovalIn: NSInsetRect(bounds, brushSize / 2, brushSize / 2))
        path.lineWidth = brushSize
        path.stroke()
    }

}

当我运行应用程序时,此视图显示正常。但是这个可设计的视图不会在Interface Builder中的场景中呈现。为什么?

When I run the app, this view appears fine. But this designable view is not rendered in my scene in Interface Builder. Why?

问题在Xcode 7.3.1中也体现出来,上面的代码也是Swift 2的再现。

The problem manifests itself in Xcode 7.3.1 with Swift 2 rendition of the above code, too.

推荐答案

问题是Interface Builder似乎没有正确呈现 @IBDesignable Interface Builder中的macOS视图,如果该视图是场景中的顶级视图。它将在iOS中,但不是macOS。在macOS中,它只在Interface Builder中呈现可设计视图,如果它是子视图,而不是顶级视图。

The issue is that Interface Builder does not appear to properly render a @IBDesignable macOS view in Interface Builder if that view is the top level view in a scene. It will in iOS, but not macOS. In macOS, it only renders the designable view in Interface Builder if it is a subview, but not the top level view.

我已经提交了错误报告。 #27817119

I have filed a bug report. #27817119

这篇关于IBDesignable视图无法渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆