Piscean
Piscean

Reputation: 3079

Can we change slide animation direction?

In my app there is a main table view. When a cell is clicked, a DetailView is created which shows details of that cell's item. On every DetailView i have next and previous buttons which helps users to go to next and previous item's DetailView without going back to RootView. When i click next button. animation is from right to left. and its same when i click previous button. Animation should be from left to right when i click previous button. Is there anyways to change that animation direction. I don't wanna use [self.navigationController popViewControllerAnimated:YES], because i have alot of items and its hard to take care of navigation stack. So is there any way i can change right to left animation to left to right when i click previous button.

Upvotes: 0

Views: 1940

Answers (1)

MHC
MHC

Reputation: 6405

It could be implemented a navigation controller and push and pop, and you don't have to deal with a messy navigation stack because what you have to do is just 1) push a view and remove the previous view from the stack (in 'next' case), or 2) insert a view into the stack in front of the current view and pop the current view (in 'previous' case).

So far, however, I see no reason to use a navigation controller here. When you are switching to a new detail view, prepare the new view as hidden and insert the view on top of the view layers. Then, create a CATransition object with desired options, unhide the new view, and deal with the previous detail view (like, remove it). For example,

CATransition transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = (nextDidPressed)? kCATransitionFromRight : kCATransitionFromLeft;
newDetailView.hidden = NO;
detailView.hidden = YES;
self.detailView = newDetailView;

The above code makes a few assumptions on your view layouts and declared properties. Make changes according to the other part of your code appropriately.

Upvotes: 1

Related Questions