Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Paging with UIScrollView?

boneheadbonehead Posts: 225Registered Users
edited November 2010 in iOS SDK Development
I'm trying to essentially recreate the Photos app image view where you can swipe your finger left and right to scroll through images. I'm setting up a UIScrollView in my view controller as follows:
UIScrollView* containerView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
containerView.backgroundColor = [UIColor blackColor];
containerView.scrollEnabled = YES;
containerView.pagingEnabled = YES;
containerView.bounces = NO;
containerView.directionalLockEnabled = YES;

self.view = containerView;

And then I'm adding a series of UIImageViews as subviews of containerView. Scrolling left/right works great (nice smooth scroll); however, the scroll does not stop on page bounds as stated in the docs for UIScrollView.pagingEnabled: "If the value of the property is YES, the scroll view stops on multiples of the view bounds when the user scrolls."

Any suggestions?
Post edited by bonehead on
· ·

Replies

  • scottiphonescottiphone Posts: 802Registered Users
    edited April 2008
    JigSaw example uses ScrollView. Might be worth looking at.
    · ·
  • boneheadbonehead Posts: 225Registered Users
    edited April 2008
    JigSaw example uses ScrollView. Might be worth looking at.

    Hrm, strangely JigSaw doesn't show up in the iPhone Dev Center "Sample Code for iPhone" section anymore. Was it part of an earlier SDK release?
    · ·
  • scottiphonescottiphone Posts: 802Registered Users
    edited April 2008
    it was one of the many examples on the site. There have been a number to disappear.
    Grab any while you can. I assume there were issues with them of one sort or another.
    · ·
  • boneheadbonehead Posts: 225Registered Users
    edited May 2008
    bonehead wrote:
    I'm trying to essentially recreate the Photos app image view where you can swipe your finger left and right to scroll through images. I'm setting up a UIScrollView in my view controller as follows:
    UIScrollView* containerView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    containerView.backgroundColor = [UIColor blackColor];
    containerView.scrollEnabled = YES;
    containerView.pagingEnabled = YES;
    containerView.bounces = NO;
    containerView.directionalLockEnabled = YES;
    
    self.view = containerView;
    

    Turns out the problem was that I had set bounces = NO. If you have bounces turned off, paging doesn't work.
    · ·
  • scottiphonescottiphone Posts: 802Registered Users
    edited May 2008
    I'd file that as a bug report.
    · ·
  • jarrednichollsjarrednicholls Posts: 1New Users
    edited August 2008
    Yeah that's definitely a bug!!
    · ·
  • schipmolderschipmolder Posts: 19Registered Users
    edited October 2008
    Has anyone found a workaround for this?

    I'm using a scrollview with paging and the scrollview should only scroll horizontally, but because of the bouncing it sometimes does bounce vertically.
    I've tried playing with the contentsize and set the directionalLockEnabled to yes, but it still bounces vertically.
    Ideally I'd like to disable the entire bouncing...
    · ·
  • vosensvosens Posts: 10Registered Users
    edited December 2008
    bonehead wrote: »
    I'm trying to essentially recreate the Photos app image view where you can swipe your finger left and right to scroll through images. I'm setting up a UIScrollView in my view controller as follows:
    UIScrollView* containerView = [[UIScrollView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    containerView.backgroundColor = [UIColor blackColor];
    containerView.scrollEnabled = YES;
    containerView.pagingEnabled = YES;
    containerView.bounces = NO;
    containerView.directionalLockEnabled = YES;
    
    self.view = containerView;
    

    And then I'm adding a series of UIImageViews as subviews of containerView. Scrolling left/right works great (nice smooth scroll); however, the scroll does not stop on page bounds as stated in the docs for UIScrollView.pagingEnabled: "If the value of the property is YES, the scroll view stops on multiples of the view bounds when the user scrolls."

    Any suggestions?

    Could you show the code where you add the images to subviews of the container? I'd like to create an image browser like yours but don't know how to add the UIImageViews. Also, if possible, do you have any insight on how you'd create a "thumbnails" page where you could tap on any image and it'll go to that image within the scrollview?

    Thanks so much for any help!!

    -Sean
    · ·
  • lajlooslajloos Posts: 35Registered Users
    edited July 2009
    containerView.bounces = YES;
    · ·
  • HenningHenning Posts: 168Registered Users
    edited September 2009
    I'm having this problem too. I don't want it to bounce, but I DO want it to page. It seems like you have to use bouncing if you want paging.

    Very frustrating...

    henning
    from <a href="http://www.chewyapps.com/" target="_blank">ChewyApps.com</a>
    · ·
  • giginhogiginho Posts: 4New Users
    edited February 2010
    Has anyone found a solution to this? I'm having the same problem...
    · ·
  • kokonaingkokonaing Posts: 23Registered Users
    edited September 2010
    bonehead wrote: »
    Turns out the problem was that I had set bounces = NO. If you have bounces turned off, paging doesn't work.

    It worked, when I also did the same. Turned on the bounces. Thanks! :)
    iobsess.png<br />
    <a href="http://itunes.apple.com/us/app/iobsess/id373554565?mt=8" target="_blank">iObsess</a>, The Ultimate Soccer Line-up App<br />
    <br />
    www.kokona
    · ·
  • NoMercyNoMercy Posts: 1New Users
    edited November 2010
    Man I dont know if I can thank you enough :)

    You saved me A lot of trouble thanks again...
    · ·
Sign In or Register to comment.