iOS creating swipe to go back

I want to make a back swipe like the one in iOS 7.I'm still new with the whole iOS development, this is what I'm currently using. Currently I have a pan gesture that detects if the user swipes back and then it just pops the navigation controller.

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];


-(void)handlePan:(UIPanGestureRecognizer *)sender{
    CGPoint tran = [recognizer translationInView:recognizer.view];
    CGPoint vel = [recognizer velocityInView:recognizer.view];
    if(vel.x > 500 && tran.x > 100){
        [self.navigationController popViewControllerAnimated:YES];
    }
}

I want the previous view to follow the finger on the pan gesture instead of just calling the pop to root. For example,

Answers


This will need a custom container view controller. In simple terms you have a view controller which holds 2 view controllers (View 1 on the left and View 2 on the right).

You attach a pan gesture to the containers view, and when the user moves, you calculate the appropriate frame for each of the sub view controllers. E.g. if the user is panning to the right, you will move the view 2 off to the right, and bring view 1 in from the left (calling the child view controller methods as needed).

When the gesture finishes you should check the final position in combination with the final direction of the pan to decide where you should place the view controllers. e.g. if you finish panning ot the right at 90% of view 1 on screen, you should move view 1 fully on screen and view 2 off screen. if you finish with 50% of each, you should use the direction of the pan to decide which view will remain on screen.


Use IIViewDeckController it's easier , and it does what you want IIViewDeck GitHub


I think in this case you should use UIScrollView, set the content size of your scroll view to width_of_view* numberOfViews and add all your view to the scroll view horizontally. when user scroll or swipe their finger over screen than show the next view. here is one Link of apple Doc will help you. don't forget to set horizontal scrolling enable in XIB or in code.


Need Your Help

Apache Spark data modelling - should I prefer denormalisation or joins for query performance?

hadoop apache-spark hdfs bigdata data-modeling

I have two logical data tables - the first contains raw data financial data with about 500 million rows per day. The second is a reference data table containing about 10,000 rows per day, with some...

Method will be shown automatically with the try catch block in android studio

android android-studio methods try-catch

In Eclipse there is the option to set a method will be created along with try catch block or not.