Reputation: 665
Maybe you guys can help me. I have three different views (Current right now in storyboard). I would like the user to swipe between the three views instead of clicking a button. Is there a easy way to enable the swiping and to allow left to right and right to left swiping?
I have been doing some research on Apples Dev. website and found some helpful stuff nothing that really explains switching between views.
Upvotes: 0
Views: 7104
Reputation: 4600
What about a UIPageControl? You can use that to detect/control requests to switch between pages, then use the delegate UIControlEventValueChanged
event to switch content in the view.
Upvotes: 0
Reputation: 88
You can consider a scroll view as well. It is good especially if you may need pagination in the end, or if you are using them for images and you may need to zoom in and out.
Upvotes: 0
Reputation: 73588
Some of the ways to switch between views in iOS -
NavigationViewController
much tighter memory management.ModalViewControllers
also.Of all the three, the first one although is more mem eff. but to animate the transition between views is difficult. So is the second one. The third gives you the maximum flexibility to provide custom animations between view transitions but you need to really take care of memory management yourself.
Now coming back to your particular problem; it seems pretty straightforward. You can take a couple of approaches -
UIScrollView
& enable only horizontal scroll & paging. Now add your views in this scrollView. upon swipe you get to see your new views.UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleViewsSwipe:)]; [swipe setDirection:UISwipeGestureRecognizerDirectionLeft]; [yourView addGestureRecognizer:swipe]; [swipe release];
With this the swipe gesture is defined on yourView
if some one swipes iOS will hit the selector handleViewsSwipe
. You handle what happens when a user swipes here.
define the selector as
- (void)handleViewsSwipe:(UISwipeGestureRecognizer *)gesture
Hope this helps..
Upvotes: 2
Reputation: 6575
Yes, you just use the UISwipeGestureRecognizer to recognize left and right swipes:
You will need to do something different for pre-iOS 3.2 if that matters to you.
Switching between views is easy enough, you can just build up three different subviews and only make the one you need visible. There are other ways to do it also, depending on the type of material you are using -- I would need more info to give a more specific answer than that.
Upvotes: 1