简体   繁体   English

界面生成器中的iOS Swift 3.0自定义视图导致重新编译和放错位置

[英]iOS Swift 3.0 custom view in interface builder causes recompiling and misplacements

i did make some custom views to be able to reuse them in different controller .xib files. 我做了一些自定义视图,以便能够在不同的控制器.xib文件中重用它们。

I do initialize them with: 我用以下方法初始化它们:

var view: UIView!
var nibName = "MyCustomView"

override init(frame: CGRect) {
    super.init(frame: frame)
    initialize()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    initialize()
}

private func initialize() {
    self.backgroundColor = Theme.colorTransparent

    let bundle = Bundle(for: type(of: self))
    let nib = UINib(nibName: self.nibName, bundle: bundle)
    self.view = nib.instantiate(withOwner: self, options: nil).first as! UIView
    self.view.frame = self.bounds
    self.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    addSubview(self.view)
    clearErrors()
}

But everytime i open a controller .xib file which contains at least one custom view, XCode starts recompiling. 但是,每次我打开包含至少一个自定义视图的controller .xib文件时,XCode就会开始重新编译。 Sometimes also the position and size of all views (not only custom) are distorted. 有时,所有视图(不仅是自定义视图)的位置和大小也会变形。 I then have to wait for the recompile to finish, before i can click the yellow triangles to fix the misplacements. 然后,我必须等待重新编译完成,然后才能单击黄色三角形以修复错误的位置。

This behaviour is very annoying... 这种行为很烦人...

Can you help me to avoid the misplacements and the recompiling so that everything runs smooth and fast? 您能否帮助我避免放错位置和重新编译,从而使一切运行起来顺畅快捷?

BTW: the custom views do work properly, it's just the waiting for the recompiling and the misplacements, which i was not able to fix 顺便说一句:自定义视图确实可以正常工作,只是等待重新编译和放错位置,我无法解决这些问题

Thank you very much 非常感谢你

Try: Editor > Automatically Refresh Views > Uncheck. 尝试:编辑器>自动刷新视图>取消选中。 This should stop the constant rebuilding, but yes, it appears like just another annoying Xcode bug. 这应该停止不断的重建,但是是的,它看起来就像是另一个令人讨厌的Xcode错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM