Scroll View does not display components

时间:2017-04-06 17:12:33

标签: swift swift3

I've started to creating UI programmatically and I'm stuck. I've added blur effect to the view and then to the blur scroll which have just one button but it does not display it. From debuging i can see that there is a button inside. What might be wrong ?

(lldb) po blurEffectViewFilters.contentView.subviews
▿ 1 element
  - 0 : <UIScrollView: 0x7fd5958a5e00; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600000253020>; layer = <CALayer: 0x6000002369c0>; contentOffset: {0, 0}; contentSize: {320, 568}>


(lldb) po blurEffectViewFilters.contentView.subviews[0].subviews
▿ 1 element
  - 0 : <UIButton: 0x7fd593f3bde0; frame = (0 0; 100 50); opaque = NO; layer = <CALayer: 0x600000236a40>>


   func initFiltersView() {
        blurEffectFilters = UIBlurEffect(style: UIBlurEffectStyle.dark)
        blurEffectViewFilters = UIVisualEffectView(effect: blurEffectFilters)
        blurEffectViewFilters.frame = view.bounds
        blurEffectViewFilters.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        blurEffectViewFilters.isHidden = true

        scrollView = UIScrollView()
        scrollView.delegate = self
        scrollView.contentSize = blurEffectViewFilters.bounds.size

        doneButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
        doneButton.backgroundColor = .white
        doneButton.setTitle("Done", for: .normal)

        scrollView.addSubview(doneButton)

        blurEffectViewFilters.contentView.addSubview(scrollView)

        view.addSubview(blurEffectViewFilters)
    }

Thanks in advance!

1 个答案:

答案 0 :(得分:1)

看起来您从未设置滚动视图的框架:

- 0 : <UIScrollView: 0x7fd5958a5e00; frame = (0 0; 0 0); clipsToBounds ...

initFiltersView()代码中,您设置的是contentSize,而不是框架。