【问题标题】:UIViewcontroller doesn't load subview(swift 3)UIViewcontroller 不加载子视图(swift 3)
【发布时间】:2016-10-26 15:06:46
【问题描述】:

我的 Storyboard 中有以下设置:

UIView -> UIScrollView->UIView(MyOwnView)

我有一个 UIViewController 并添加了一个 UIScrollView,在 UIScrollView 中我添加了一个 UIView。这个 UIView 是一个自定义的 UIView:

class MyOwnView: UIView {


    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code


       self.backgroundColor = UIColor(patternImage: (UIImage(named: "menschVorne")?.resize(CGSize(width: rect.width, height: rect.height)))!)
print("loaded")

    }
}

当我加载 UIViewController 时,没有显示任何图像。当 UIViewController 出现时会调用 draw(rect..) 函数。有人可以帮我吗?

致以诚挚的问候!

【问题讨论】:

  • 你的scrollView设置ContentSize了吗?见here
  • 是的,这一切都设置正确。我在这个 UIView 中绘制。如果我与 UIView 交互(点击它),则图像显示正确。

标签: ios uiview swift3


【解决方案1】:

我可以找到解决办法:

let image = UIImage(named: "menschVorne")?.resize(CGSize(width: rect.width, height: rect.height))
        let imageView = UIImageView(image: image)



            self.addSubview(imageView)
            imageView.center = self.center
self.sendSubview(toBack: imageView)

而不是

self.backgroundColor = UIColor(patternImage: (UIImage(named: "menschVorne")?.resize(CGSize(width: rect.width, height: rect.height)))!)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 2015-02-21
    • 2017-11-21
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多