Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 自定义控件仅在iPhone 6和iPhone 6s模拟器上显示_Ios_Iphone_Swift_Uiview - Fatal编程技术网

Ios 自定义控件仅在iPhone 6和iPhone 6s模拟器上显示

Ios 自定义控件仅在iPhone 6和iPhone 6s模拟器上显示,ios,iphone,swift,uiview,Ios,Iphone,Swift,Uiview,我正在创建一个自定义控件。 当我运行程序时,自定义控件不会显示在iPhone 6和iPhone 6s模拟器上。在iPhone7、iPhone7 plus、iPhoneSE等设备上,一切正常 在我的控件中,我放置一个UIView(backView)在其上绘制路径,并在其上放置一个UIImageView和一个ui按钮。它就像是一个有一个按钮的酒吧 以下是我的资料的相关部分 import UIKit @IBDesignable class ButtonBar: UIControl { //

我正在创建一个自定义控件。 当我运行程序时,自定义控件不会显示在iPhone 6和iPhone 6s模拟器上。在iPhone7、iPhone7 plus、iPhoneSE等设备上,一切正常

在我的控件中,我放置一个
UIView
backView
)在其上绘制路径,并在其上放置一个
UIImageView
和一个
ui按钮。它就像是一个有一个按钮的酒吧

以下是我的资料的相关部分

import UIKit

@IBDesignable
class ButtonBar: UIControl {

    // -- MARK: controls
    @IBOutlet weak var backView: UIView!
    @IBOutlet weak var image: UIImageView!
    @IBOutlet weak var actionButton: UIButton!
    @IBOutlet weak var buttonTopConstraint: NSLayoutConstraint!

    // -- MARK: customize properties
    // some @IBInspectable properties here...

    // -- MARK: other properties
    weak var view: UIView!
    var backgroundLayer: CAShapeLayer!

    // -- MARK: init()s
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupSubViews()
    }

    convenience init() {
        self.init(frame: CGRect.zero)
    }

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

    // -- MARK: override functions
    override func layoutSubviews() {
        guard view != nil else {
            return
        }

        view.frame = bounds
        self.refresh()
    }

    // -- MARK: other functions
    func loadViewFromNib() -> UIView {
        let clazz = type(of: self)
        let bundle = Bundle(for: clazz)
        let nib = UINib(nibName: "\(clazz)", bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
        return view
    }

    func setupSubViews() {
        view = loadViewFromNib()
        view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]
        self.addSubview(view)
        self.backgroundLayer = CAShapeLayer()
        self.backView.layer.addSublayer(self.backgroundLayer)
        self.refresh()
    }

    public func refresh() {
        let path = UIBezierPath()
        // code to create the path...
        path.close()

        self.backgroundLayer.path = path.cgPath
        self.backgroundLayer.fillColor = self.barColor.cgColor
        self.backgroundLayer.strokeColor = self.borderColor.cgColor
        self.backgroundLayer.lineWidth = CGFloat(self.borderWidth)

        self.backView.layer.replaceSublayer(self.backgroundLayer, with: self.backgroundLayer)

        self.image.image = self.buttonImage

        self.buttonTopConstraint.constant = CGFloat(t - to)
    }
}
我只是将UIView拖到我的故事板中,并将其类设置为这个自定义控件

如果我覆盖
draw(:)
函数并调用其中的
refresh()
函数,它可以在iPhone 6[s]模拟器上工作。但我知道这不是一个好的做法,因为有些性能问题

我的代码是否有问题,或者只是iPhone 6[s]模拟器的一个bug

==更新== 我将我的项目发送给使用xcode 8.2的其他人(我刚刚将其升级到8.3.1),他删除了底部约束,并用相同的值重新添加它。问题解决了

我收到了他发给我的项目,删除了约束,然后又添加了一次。这个问题没有重现。虽然我对我最初的项目做了同样的处理,但问题仍然存在


这是xcode的错误吗

self.buttonopconstraint.constant=CGFloat(t-to)
中,什么是
t
to
t
to
是根据
边界、高度和其他属性计算的变量。它们用于确定按钮的位置。在其他模拟器上,它运行良好,因此我相信它们具有正确的价值。