I have some picture, let's say like rectangular piece of paper. I want to position it on the center of the screen, and when user slides left or right with its finger (let's say left), that piece of paper should go left (with the finger), and from the right should come new piece of paper with some new information.
I hope that my description isn't confusing. I guess that this functionality should be easy to do with iOS SDK, I just don't know what to use ...
Thanks for any help ;)
You'll want to use a UIScrollView
for that. You add your "pieces of paper" -- which I assume will be views (UIImageView
s perhaps?) -- as subviews, and set the contentSize
property of the scroll view to fit them all. You might also want to set the showsHorizontalScrollIndicator
property of the scroll view to NO
, to hide the scroller.
Off the top of my head, I imagine something like this:
UIScrollView *aScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
aScrollView.showsHorizontalScrollIndicator = NO;
CGFloat paperWidth = 320;
NSUInteger numberOfPapers = 5;
for (NSUInteger i = 0; i < numberOfPapers; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(paperWidth * i, 0, paperWidth, aScrollView.bounds.size.height)];
imageView.image = LOAD_IMAGE_HERE...;
[aScrollView addSubview:imageView];
}
CGSize contentSize = CGSizeMake(paperWidth * numberOfPapers, aScrollView.bounds.size.height);
aScrollView.contentSize = contentSize;
[self.view addSubview:aScrollView];
来源:https://stackoverflow.com/questions/8777450/ios-horizontally-sliding-items