PagingEnabled for multiple pages in UIScrollView


Edit: See the answer below.

I finally give up and come here to ask you for my problem...

I'm using a UIScrollView for a scrolling menus with little icons. On each page, with paging enabled, there's an icon in the center, and 2 and a half other visible icons on the left and right. I can move from one icon to its neighbour, and that is fine, but the point is that if I do a fast scrolling, it will not move from more than 3 icons, which is the width of the screen.

What I would want is to be able to scroll on more than 3 icons, and that the magnet behaviour is only triggered when it's slowing down.

I've tried to schedule the scroll view to calculate its velocity, and set the pagingEnabled attribute to NO when it's moving fast and YES again when it's slowing down, but as soon as it is set to YES, the view comes back very fast at its original position, as if it was not detecting that I had brought it to a new page. Would anyone know why it does this? And if I have a way to tell the view "ok, now the paging is enabled but look, you're 15 pages later. Just center on the current page, don't come back at the beginning."

Here's my update function (if it can help):

-(void)update:(ccTime)dt { float velocity = fabsf((self.previousOffset-self.scrollView.contentOffset.y)/dt); self.previousOffset = self.scrollView.contentOffset.y; CCLOG(@"Velocity: %f", velocity); if(self.scrollView.pagingEnabled) { if(velocity > 100) { self.scrollView.pagingEnabled = NO; } } else { if(velocity < 100) { self.scrollView.pagingEnabled = YES; } } }


I finally found a solution, which was pretty obvious, but that I did not see at the beginning, by using setContentOffset on the scrollView.

Here is the new update function:

-(void)update:(ccTime)dt { float velocity = 1000; if(self.previousOffset) { velocity = fabsf((self.previousOffset-self.scrollView.contentOffset.y)/dt); } self.previousOffset = self.scrollView.contentOffset.y; if(velocity < 300) { CGSize screenSize = [[CCDirector sharedDirector] winSize]; float halfScreen = screenSize.width/2; CCLayer *panel = (CCLayer *)[self getChildByTag:1]; SQScrollViewMenu *menu = (SQScrollViewMenu *)[panel getChildByTag:1]; SQMissionItem *currentItem = (SQMissionItem *)[menu getChildByTag:currentPage]; float contentOffsetY = [self.scrollView contentOffset].y; CCLOG(@"Currentpage: %i ; currentoffsetY: %f", currentPage, contentOffsetY); float distance = contentOffsetY + [currentItem position].x - halfScreen + panel.position.x + menu.position.x + panel.parent.position.x - 60; CCLOG(@"Which gives a distance of: %f", distance); [self.scrollView setContentOffset:CGPointMake(0, distance) animated:YES]; self.previousOffset = 0; [self unschedule:@selector(update:)]; CCLOG(@"Is unscheduled"); } }

And it is almost working... at least, it is on simulator. But as soon as I try it on my iPhone 4, it does not work anymore. It always go into that update function, but 7 times among 8, it just blocks the scrollView as it is and does not drags it back to the position I give it... but sometimes it does.

Would anyone have an idea? I found similar issues on the net, but none of them could resolve this...


  • AngularJS binding base 64 encoded image slowing down page load
  • PyTorch - shape of nn.Linear weights
  • Running the same select query multiple times with different parameters: Mysql
  • Xcode, UIscrollView and pagination
  • OpenCV on iOS: binary size, load time, speed etc.
  • Asp.net mvc form post and paging
  • Could we use owl:sameAs in an OWL restriction?
  • How to zoom particular part of UIScrollView?
  • “tkinter.TclError: invalid command name” error after calling root.destroy()
  • All bodies have rigidbody 2d and boxcollider2d and there's no collision
  • LibGDX Multiply Vector2 with float value
  • Code to disable magnifier, set wallpaper, and save image in Google Chrome?
  • onActivityResult() not called after startActivityForResult() with Intent.ACTION_GET_CONTENT
  • @ngboostrap Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap�
  • Where to put clearQueue in jQuery code
  • How to get value of the slider, when touchend or mouseup events are used?
  • Creating interactive SVG maps for a web portal
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • WPF Animation doesn't run first time
  • Missing permission to control media error on Android 5/L
  • IE11 textarea loses focus if another textarea is disabled
  • Spring integration inbound-gateway Fire an event when queue is empty
  • In matplotlib, how do you change the fontsize of a single figure?
  • Cloud Code function running twice
  • Who propagate bugfixes across branches (corporate development)?
  • xcode don't localize specific strings
  • Combining two different ActiveRecord collections into one
  • Why cepheus don't send int without quotes to orion?
  • Automatically associate new Sonar project with custom quality profile and quality gate
  • Tamper-proof configuration files in .NET?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • ilmerge with a PFX file
  • HTML download movie download link
  • Adding custom controls to a full screen movie
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • Running Map reduces the dimensions of the matrices
  • reshape alternating columns in less time and using less memory