Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iLoveDeveloping

Suspended
Original poster
Sep 24, 2009
596
2,366
Ireland
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?
 
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?
 
...its not behaving like i want it to
What's it doing instead?

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?
You probably want to find another way other than Interface Builder to add your images then.
 
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?
 
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.
I guess you missed the part where I said you'll want to enable paging.

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?
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.
 

Attachments

  • Screen shot 2009-10-28 at 5.17.00 PM.png
    Screen shot 2009-10-28 at 5.17.00 PM.png
    17.2 KB · Views: 361
: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...
 
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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.