我正在尝试完成类似iOS weather app的滚动运动。以下gif显示了我到目前为止所取得的成就。
我将标题视图放在主视图的顶部,并根据位于主视图上的滚动视图更改其高度。然后,我通过标题视图高度常数从滚动视图的顶部到主视图的顶部添加了一个约束。这是代码
from operator import add
import sys
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
## Constants
APP_NAME = "PythonStreamingDirectKafkaWordCount"
##OTHER FUNCTIONS/CLASSES
def main():
sc = SparkContext(appName="PythonStreamingDirectKafkaWordCount")
ssc = StreamingContext(sc, 2)
brokers, topic = sys.argv[1:]
kvs = KafkaUtils.createDirectStream(ssc, [topic], {"metadata.broker.list": brokers})
lines = kvs.map(lambda x: x[1])
counts = lines.flatMap(lambda line: line.split(" ")) \
.map(lambda word: (word, 1)) \
.reduceByKey(lambda a, b: a+b)
def process(RDD):
#RDD.pprint()
kvs2=RDD.map()
kvs2.saveAsTextFiles('path')
#kvs.foreachRDD(lambda x: process(x))
#kvs1=kvs.map(lambda x: x)
kvs.pprint()
kvs.saveAsTextFiles('path','txt')
ssc.start()
ssc.awaitTermination()
if __name__ == "__main__":
main()
在这里,我调整了标题视图的高度,并更改了滚动视图内容的偏移量,以强制滚动视图直到其到达折叠的标题视图的底部之前才滚动。为了向上移动滚动视图,我更改了原点func scrollViewDidScroll(_ scrollView: UIScrollView) {
let delta = scrollView.contentOffset.y - previousContentOffset
if delta > 0 && headerView.frame.height > collapsedHeaderHeight && scrollView.contentOffset.y > 0 {
direction = .up
headerView.frame.size.height = max(collapsedHeaderHeight, headerView.frame.height - delta)
scrollView.contentOffset.y -= delta
}
if delta < 0 && headerView.frame.height < expandedHeaderHeight && scrollView.contentOffset.y < 0 {
direction = .down
headerView.frame.size.height = min(headerView.frame.height - delta, expandedHeaderHeight)
scrollView.contentOffset.y -= delta
}
topConstraint.constant = headerView.frame.height
scrollView.frame.origin.y = headerView.frame.maxY
scrollView.contentSize.height = contentView.bounds.height + headerView.bounds.height
headerView.clipsToBounds = true
previousContentOffset = scrollView.contentOffset.y
}
坐标并修改了内容大小。我使用了y
和scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
委托方法来自动向上或向下移动滚动视图并防止剪切标题视图。
scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
到目前为止一切正常。显然,如果我尝试从标题视图滚动,则将无法正常工作。因此,我将滚动视图嵌入到固定到主视图边界的辅助滚动视图中。但是我无法使滚动工作。一些帮助将不胜感激。