1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Swiping Photo Views

Discussion in 'iPhone/iPad Programming' started by iLoveDeveloping, Oct 28, 2009.

  1. macrumors regular


    Just wondered if anyone had the code to do swiping on views, i have a new App that has photos in it and i want the user to be able to just swipe there finger along the screen and go to the next photo. How is this done?
  2. macrumors regular

    Oh, and i have a picture on each Xib, forgot to mention that..
  3. Moderator


    Staff Member

    A simple way to do this is add the images as subviews of a scroll-view and then enable paging.
  4. macrumors regular

    OH ok, that sounds better, would only need one view then, can you tell me how to do this? or show me where i can find out?
  5. Moderator


    Staff Member

  6. macrumors regular

    Ok i got something going here, i have the scroll view all set up and it works, but i have two more questions now, its not behaving like i want it to. I want to create something like the default 'Photos' on every iPhone, i want to go through each photo and have it stop at each one.

    Here is the code im using:


    #import "MainView.h"
    @implementation MainView
    - (IBAction)gotoscrollview {
    	myscrollview.contentSize = CGSizeMake(2000, 480);
    	[self addSubview:myscrollview];
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    @interface MainView : UIView {
        IBOutlet UIView *myextraview;
        IBOutlet UIScrollView *myscrollview;
    - (IBAction)gotoscrollview;
    And two, this might seem silly, but say i want to put in 10 photos, and i have one UIScrollingView to have all those photos in, how do i fit them all in in interface builder, a mac screen can not fit in 10 photos wide, how do i fit them all in one big line?
  7. Moderator


    Staff Member

    What's it doing instead?

    You probably want to find another way other than Interface Builder to add your images then.
  8. macrumors regular

    its just sliding along without stopping, like it just slides according to how hard a flick my finger and stops when it slows down, not stopping at the next image like i want it to, like the default 'Photos' App on all iPhones.

    How do other people do that? i mean even in Photos App from Apple, how do they do that? they don't put your pictures into interface builder, is there a way just to link them all into the view?
  9. Moderator


    Staff Member

    I guess you missed the part where I said you'll want to enable paging.

    They do it programatically. You already know about addSubview: so you already know of the kernel of one technique. Plus, I believe there are libraries out there that will give you the functionality you desire without having to do all the heavy-lifting yourself.
  10. macrumors regular

    How would one enable paging? There is no tick box for that in IB and i don't know any code to do that?
  11. Moderator


    Staff Member

    Well, that's not quite true, is it?

    Attached Files:

  12. macrumors regular

    :eek: Ooooops!

    Sorry, did not see that! Didn't get much sleep last night, (9 hours doing an app :()


    I will see how that works out...
  13. macrumors regular

    Does it auto detect the photos 'pages'? To know which the next one is?

    Cos it seems to be doing the same.. Well, a little bit more jumpy, its jumping to the next image like i wanted but then keeps on going all the way to the next one at the end Until i stop it with my finger. (I'm only working with 3 images to start.)

    I no i am asking a lot but this is the final thing for my App and it is driving me crazy! I just want to get it working...
  14. Moderator


    Staff Member

    As long as the scrolling stops and you don't have two pages semi-displayed in the same view then, yes, it is working as expected.

Share This Page