现在,每一次按下按钮,分数就会上升。一旦得分达到3分,滚动视图的高度就会增加。我怎么能做到这一点,所以每次按下按钮,高度就会增加50倍。
@IBAction func enterScore(_ sender: Any) {
score += 1
THESCROOL.contentSize.height = 1000
if score >= 3 {
THESCROOL.contentSize.height = 5000
}}发布于 2017-05-24 16:49:39
我不确定我完全理解你的问题。你想做这样的事吗?
@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
}发布于 2017-05-24 17:14:53
我也不确定我是否完全理解你的问题,但只是为了补充@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
}
}发布于 2017-05-24 17:14:48
以全局变量作为计数器,将其设置为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)
}注意:内容大小是增加的,而不是帧高,因此您将看到滚动视图的滚动区域将增加。
https://stackoverflow.com/questions/44164060
复制相似问题