2017-05-24 58 views
0

现在,每次按下按钮a分数都会上升。一旦分数达到3,滚动视图高度就会增加。我怎样才能做到这一点,所以每次按下按钮时,高度会增加50倍无限次。如何使用循环来增加滚动视图大小(swift3)

@IBAction func enterScore(_ sender: Any) { 
     score += 1 


      THESCROOL.contentSize.height = 1000 
      if score >= 3 { 
       THESCROOL.contentSize.height = 5000 

      }} 

回答

0

不知道我完全理解你的问题。你想做这样的事吗?

@IBAction func enterScore(_ sender: Any) { 
    score += 1 

    // every time the button is pressed, the contentHeight is increased by 50 
    THESCROOL.contentSize.height = THESCROOL.contentSize.height + 50 
} 
0

以全局变量作为计数器设置为0。

var counter = 0 

则该函数添加到按钮动作

func btnTempClicked(sender:UIButton) -> Void { 

    counter = counter+1 
    let height = CGFloat(50*counter) 

    scrlVw.contentSize = CGSize(width: scrlVw.frame.size.width, height: height) 

} 

NB:内容尺寸增加,而不是框架高度,所以你会看到滚动视图的滚动区域会增加。

编码快乐......

0

不知道我完全理解你的问题太多,但只补充@bughana答案

@IBAction func enterScore(_ sender: Any) { 
    //add score on button pressed 
    score += 1  

    //just for every time the score is multiple of 3 
    if 3 % 3 == 0 
     //increase 50 with operator += 
     THESCROOL.contentSize.height += 50  
    } 
}