7. Two-Finger Gesture to Change Views

In this example we will use a 2 finger gesture to switch between our parent view, which contains all of our switches, sliders, buttons etc, and out credit view we recently made.

2-Finger Swipe Gesture

Starting with our parent view (DOViewController), we first add a new gesture object to the view by dragging the Swipe Gesture onto the view.  We then add an action to the .h file that is attached to the gesture to we can call a function when the gesture is recognized on the iPhone.  Our .h file now has everything implemented so far, along with the new IBAction: showCreditViewGesture and the new object DOCreditViewController *creditView, we also import the new view .h file:

Now we will go to the .m file and create a new “subview” so when we call it it is ready to transition.  To do this we init the DOCreditViewController:

Now that we have the second view we can make the gesture we added switch to the second view. To do this all we have to do is dismiss our current view and present our child view we declared above:

Now we need a we to get back to our main view.  So we are going to implement the method we made for our second view.  This is much like our other transition.  On our init we call a function that tells how we transition into this view, describing the animation as a flip:

Now to get back to the main view we just dismiss out current view:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s