2017-04-06 77 views
0

我已經開始以編程方式創建UI,並且卡住了。我爲視圖添加了模糊效果,然後添加了只有一個按鈕但不顯示它的模糊滾動。從調試我可以看到裏面有一個按鈕。什麼可能是錯的?滾動視圖不顯示組件

(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) 
    } 

在此先感謝!

回答

1

它看起來像你從來沒有設置滾動視圖的框架:

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

initFiltersView()代碼,你設置contentSize,而不是框架。

+0

謝謝!我忘記了這一點,沒有「新鮮眼球」就無法看到這一點。 – yerpy