iOS determines the scrolling direction of the scrolling view

Source: Internet
Author: User

PushListView.h

@interface Pushlistview:uiview<uitableviewdelegate,uitableviewdatasource

{

CGFloat contentoffsety;

CGFloat oldcontentoffsety;

CGFloat newcontentoffsety;

}

pushlistview.m

Start dragging the view

-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView{

Contentoffsety = Scrollview.contentoffset.y;

}

Call this method when scrolling (after the finger leaves the screen )

-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView{

//nslog (@ "scrollview.contentoffset:%f,%f", Scrollview.contentoffset.x, Scrollview.contentoffset.y);

Newcontentoffsety = Scrollview.contentoffset.y;

if (newcontentoffsety > Oldcontentoffsety && oldcontentoffsety > Contentoffsety) { // scroll up

NSLog (@ "up");

} Else if (Newcontentoffsety < oldcontentoffsety && Oldcontentoffsety < contentoffsety) {// scroll down

NSLog (@ "down");

} Else {

NSLog (@ "dragging");

}

if (scrollview.dragging) { // drag

NSLog (@ "scrollview.dragging");

NSLog (@ "contentoffsety:%f", contentoffsety);

NSLog (@ "newcontentoffsety:%f", scrollview.contentoffset.y);

if ((scrollview.contentoffset.y-contentoffsety) >5.0f) { // Pull up

// Hide navigation bar and options Bar

[Self layoutview];

[_viewcontroller.navigationcontroller Setnavigationbarhidden:yesanimated:YES];

[_viewcontroller.navigationcontroller Settoolbarhidden:!hidden Animated:yes];

_viewcontroller.tabbarcontroller.tabbar.hidden =YES;

} Elseif ((CONTENTOFFSETY-SCROLLVIEW.CONTENTOFFSET.Y) > 5.0f) { // drag down

// show navigation bar and options Bar

[Self layoutview];

[_viewcontroller.navigationcontroller Setnavigationbarhidden:noanimated:YES];

[_viewcontroller.navigationcontroller Settoolbarhidden:no Animated:yes];

_viewcontroller.tabbarcontroller.tabbar.hidden =NO;

} Else {

}

}

}

Complete the drag (call this method when scrolling stops, before the finger leaves the screen )

-(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate{

NSLog (@ "scrollviewdidenddragging");

Oldcontentoffsety = Scrollview.contentoffset.y;

}

iOS determines the scrolling direction of the scrolling view

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.