Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 682503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:36:11+00:00 2026-05-14T01:36:11+00:00

There seem to be many questions asked about this subject here on stackoverflow, but

  • 0

There seem to be many questions asked about this subject here on stackoverflow, but none of them touch on the updates made in 3.0. After mucking around for hours on end I finally found out, that nested scroll views (in my case web views inside a scroll view) are fully supported, however the example given at http://developer.apple.com/iphone/library/documentation/WindowsViews/Conceptual/UIScrollView_pg/Introduction/Introduction.html is pretty basic.

I have a main scroll view with paging enabled, with web views laid out as subviews, so that I can page left and right changing different web views, but also scroll up and down inside the subviews.

In essence this seems to work fine, however what I can’t figure out is how to stop the parent scroll view from paging left or right once the user has already started scrolling the web view. Essentially I’d like to lock the scrolling to whichever direction it started with. Funnily enough, this works fine if I start paging first, but if I start scrolling up or down first it also lets page at the same time (during the same began-moved-ended cycle).

The stocks app for example locks the scrolling properly.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:36:11+00:00Added an answer on May 14, 2026 at 1:36 am

    EDIT: this is completely broken on iOS 4.0. I will update this once I figure out what’s wrong.

    Since UIWebView doesn’t play very nicely with the automagical nested scrolling introduced in 3.0 and sending touchesBegin/Moved/Ended to a UIScrollView is no longer supported here’s what I came up with.

    I added a transparent UIView subclass on top of all of the other views and made it catch all touches.
    When touches begin I forward that to the currently active UIWebView and start a short timer (or rather another thread that uses usleep() to sleep for a little bit – in my experience the main thread can get locked up when a lot of touch events are incoming and timers can go way off).

    In touchesMoved I check if the timer I started hasn’t expired – if it hasn’t and fabs(location.x – lastLocation.x) > fabs(location.y – lastLocation.y) then it looks like the user is trying to page (this could be adjusted with a multiplier, but for now this seems to be just the sweet spot).
    If it’s been determined that the user is trying to page I send the web view touchesCancelled and start adjusting the scroll view’s contentOffset.x accordingly.

    In touchesEnded, if it’s been determined that the user was paging, I apply some Newtonian physics to see if the touch, along with some kinetic continuation of the scrolling would’ve been enough to cross over to the next page (more than half of the next page is visible). If so I animate the scroll to continue based on the speed of the scroll.

    Warning: This code is horrible due to trying a billion different things. I haven’t had a chance to clean it up yet. Hope this helps someone.

    -(void)timer {
        usleep(250000);
        expired = YES;
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        paging = NO;
        expired = NO;
        determined = NO;
    
    
        if(navManager == nil) {
            navManager = [[[[UIApplication sharedApplication] delegate] viewController] navManager];
        }
    
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:self];
    
        touchStartX = location.x;
        touchStarted = touch.timestamp;
    
        [NSThread detachNewThreadSelector:@selector(timer) toTarget:self withObject:nil];
    
        [[navManager.currentNavItem.webView hitTest:CGPointZero withEvent:event] touchesBegan:touches withEvent:event];
    }
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        if(!paging) {
            [[navManager.currentNavItem.webView hitTest:CGPointZero withEvent:event] touchesCancelled:touches withEvent:event];
        }
    
    }
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        if(!paging) {
            [[navManager.currentNavItem.webView hitTest:CGPointZero withEvent:event] touchesEnded:touches withEvent:event];
        }
        else {
            UITouch *touch = [touches anyObject];
            CGPoint location = [touch locationInView:self];
            NSTimeInterval touchLasted = touch.timestamp - touchStarted;
            CGFloat touchLen = location.x - touchStartX;
            float dir = touchLen/fabs(touchLen);
            float touchSpeed = touchLen/touchLasted;
            float deAccelRate = -3000.0;
            float timeToDeAccel = (-touchSpeed) / deAccelRate;
            float averageVelocity = touchSpeed / 2.0;
            float couldTravel = averageVelocity*timeToDeAccel;
    
            if(couldTravel > navManager.scrollView.frame.size.width/2.0) {
                couldTravel = navManager.scrollView.frame.size.width/2.0;
            }
            couldTravel = dir*couldTravel;
    
            NSLog(@"could travel: %f, touchSpeed: %f, timeToDeAccel = %f, averageVelocity: %f", couldTravel, touchSpeed, timeToDeAccel, averageVelocity);
    
            int page = round((navManager.scrollView.contentOffset.x - couldTravel) / navManager.scrollView.frame.size.width);
            if(page < 0) 
                page = 0;
            else if(page > round(navManager.scrollView.contentSize.width / navManager.scrollView.frame.size.width) - 1) 
                page = round(navManager.scrollView.contentSize.width / navManager.scrollView.frame.size.width) - 1;
    
            CGPoint newOffset = CGPointMake(page*navManager.scrollView.frame.size.width, navManager.scrollView.contentOffset.y);
            float needToMove = fabs(newOffset.x - navManager.scrollView.contentOffset.x);
            float timeToAnimate = needToMove / averageVelocity;
    
            [UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDelegate:nil];
            [UIView setAnimationDuration:timeToAnimate];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
            navManager.scrollView.contentOffset = newOffset;
            [UIView commitAnimations];
        }
    }
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [touches anyObject];
        CGPoint location = [touch locationInView:self];
        CGPoint lastLocation = [touch previousLocationInView:self];
    
        if(!determined && !expired) {
    
            if(fabs(location.x - lastLocation.x) > fabs(location.y - lastLocation.y)) {
                NSLog(@"PAGE!!");
                paging = YES;
                [[navManager.currentNavItem.webView hitTest:CGPointZero withEvent:event] touchesCancelled:touches withEvent:event];
            }
            else
                [navManager.scrollView touchesCancelled:touches withEvent:event];
    
            determined = YES;
        }
    
        if(!paging) 
            [[navManager.currentNavItem.webView hitTest:CGPointZero withEvent:event] touchesMoved:touches withEvent:event];
    
        else {
            float xScroll = navManager.scrollView.contentOffset.x-(location.x - lastLocation.x);
    
            CGPoint newOffset = CGPointMake(xScroll, navManager.scrollView.contentOffset.y);
            navManager.scrollView.contentOffset = newOffset;
        }
    }
    

    There’s a few more things to add to make it feel more native, but this should be a good starting point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There seem to many ways to skin this particular cat - but which is
I know questions like this have been asked numerous times, but not quite this
There seem to be many ways to define singletons in Python. Is there a
There seem to be many options to create an XML document in .NET. What's
There seem to be many excellent web frameworks for Python. Has anyone used any
There seem to be so many color wheel, color picker, and color matcher web
I know that there are similar questions which are already answered, but I am
There seem to be two rival Eclipse plugins for integrating with Maven: m2Eclipse and
There seem to be a number of weird things one could do if one
Duplicate : Using a regular expression to validate an email address There seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.