简体   繁体   中英

Drag UIView containg UIScrollView

I have been having trouble trying to drag a UIView that has a UIScrollView within it. The UIView drags up from the bottom of the screen, when it has hit the top you can use the UIScrollView inside it. When the user scrolls to the top of the UIScrollView, the UIView should drag down with their finger.

It should work like the Google Maps popup when you click a pin.

Update : I can get the dragging up of the UIView working (touchesMoved) that changes the Y value. The main functionality I am having problems with is the dragging down of the UIView when the user touches inside the UIScrollView. I want the user to still be able to drag the scrollview as normal until it reaches the top at which point the dragging action should then move the parent UIView down off the screen.

Update 2: This is the code you suggested to turn off the user interaction:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if(scrollView.contentOffset.y<=0){
        scrollView.userInteractionEnabled = NO;
    }else{
        scrollView.userInteractionEnabled = YES;
    }
}

Most apps handle this scenario by using the UIScrollViewDelegate method scrollViewDidScroll.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    // check the scrollView.contentOffset.y to see if you 
    // have reached the top of the scroll view.
}

You can then check the contentOffset and continue with your dragging code the way you want.

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