简体   繁体   中英

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.

When I scroll down, the view1 is enlarged (this works fine, it creates a zoom). 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. So the contentView should not scroll until we reach y=0.

How could I do that?
The problem is : if I scroll up, the contentView scrolls. So I don't see how to check the contentView, because the frame will go up, but the contentView also at the same time.

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. Simply try to set scrollView.contentOffset = CGPointZero in your first if-clause.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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