Swiping Photo Views

Discussion in 'iOS Programming' started by iLoveDeveloping, Oct 28, 2009.

  1. iLoveDeveloping macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #1
    Hey,

    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. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #2
    Oh, and i have a picture on each Xib, forgot to mention that..
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    A simple way to do this is add the images as subviews of a scroll-view and then enable paging.
     
  4. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #4
    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. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
  6. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #6
    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:

    .h:

    Code:
    #import "MainView.h"
    
    @implementation MainView
    - (IBAction)gotoscrollview {
    	myscrollview.contentSize = CGSizeMake(2000, 480);
    	[self addSubview:myscrollview];
        
    }
    @end
    
    .m:
    Code:
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    
    @interface MainView : UIView {
        IBOutlet UIView *myextraview;
        IBOutlet UIScrollView *myscrollview;
    }
    - (IBAction)gotoscrollview;
    @end
    
    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. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    What's it doing instead?

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

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #8
    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. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    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. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #10
    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. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    Well, that's not quite true, is it?
     

    Attached Files:

  12. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #12
    :eek: Ooooops!

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

    Thanks,

    I will see how that works out...
     
  13. iLoveDeveloping thread starter macrumors regular

    Joined:
    Sep 24, 2009
    Location:
    Ireland
    #13
    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.)



    EDIT:
    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. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    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