PDA

View Full Version : Swiping Photo Views




iLoveDeveloping
Oct 28, 2009, 02:18 PM
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?



iLoveDeveloping
Oct 28, 2009, 02:21 PM
Oh, and i have a picture on each Xib, forgot to mention that..

dejo
Oct 28, 2009, 02:42 PM
A simple way to do this is add the images as subviews of a scroll-view and then enable paging.

iLoveDeveloping
Oct 28, 2009, 02:58 PM
A simple way to do this is add the images as subviews of a scroll-view and then enable paging.

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?

dejo
Oct 28, 2009, 03:14 PM
Using NSXMLParser to Pull UIImages From the Web (http://icodeblog.com/category/interface-builder/)

This covers other topics, like XML parsing, that you may want to ignore but should get you headed in the right direction. If not, Google around. There's more out there.

iLoveDeveloping
Oct 28, 2009, 05:03 PM
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:

#import "MainView.h"

@implementation MainView
- (IBAction)gotoscrollview {
myscrollview.contentSize = CGSizeMake(2000, 480);
[self addSubview:myscrollview];

}
@end

.m:

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

dejo
Oct 28, 2009, 05:15 PM
...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.

iLoveDeveloping
Oct 28, 2009, 05:26 PM
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?

dejo
Oct 28, 2009, 05:33 PM
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.

iLoveDeveloping
Oct 28, 2009, 06:09 PM
I guess you missed the part where I said you'll want to enable paging.


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

dejo
Oct 28, 2009, 06:19 PM
There is no tick box for that in IB...
Well, that's not quite true, is it?

iLoveDeveloping
Oct 28, 2009, 06:25 PM
:o 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...

iLoveDeveloping
Oct 28, 2009, 06:32 PM
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...

dejo
Oct 28, 2009, 06:44 PM
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.