简体   繁体   English

如何在滚动contentView之前向上滚动scrollview的框架? (当scrollView从屏幕中间开始时)

[英]How to move up scrollview 's frame before scrolling contentView? (when scrollView starts at the middle of the screen)

My scrollview is at the vertical center of the screen, and a view1 is above it, at y=0. 我的scrollview在屏幕的垂直中心,view1在屏幕的上方,y = 0。

When I scroll down, the view1 is enlarged (this works fine, it creates a zoom). 当我向下滚动时,view1会放大(这很好,它会创建一个缩放)。 When I scroll up, I would like to move the scrollView up to the top of the screen (y=0), and only there, start the normal scrolling to show the rest of the contentView. 当我向上滚动时,我想将scrollView向上移动到屏幕顶部(y = 0),然后仅在此处开始正常滚动以显示contentView的其余部分。 So the contentView should not scroll until we reach y=0. 因此,contentView在到达y = 0之前不应该滚动。

How could I do that? 我该怎么办?
The problem is : if I scroll up, the contentView scrolls. 问题是:如果我向上滚动,contentView也会滚动。 So I don't see how to check the contentView, because the frame will go up, but the contentView also at the same time. 因此,我看不到如何检查contentView,因为框架会上升,但contentView也会同时出现。

Here is my method to scroll : 这是我的滚动方法:

func scrollViewDidScroll(scrollView: UIScrollView) {
    if scrollView.contentOffset.y > 0 && scrollView.frame.origin.y > 0 {
        //goes up before we scroll contentView
        scrollView.frame = CGRectOffset(scrollView.frame, 0, ........ ) //HERE
    }

    //enlarge view
    else if scrollView.contentOffset.y < 0 { //... }

A possible approach would be to simply "reset" the scrollview's contentOffset.y value anytime it is dragged and your frame is not yet positioned at the top. 一种可能的方法是,只要拖动滚动视图的contentOffset.y值并且您的框架尚未位于顶部,就可以简单地对其进行“重置”。 Simply try to set scrollView.contentOffset = CGPointZero in your first if-clause. 只需在第一个if子句中尝试设置scrollView.contentOffset = CGPointZero

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM