Problems with ECSlidingViewController with topview animation

I am using ECSliding and I have this problem!

My project has the following files:

InitViewController (ECSlidingController)

FirstViewController (UIViewController)

SecondViewController (UIViewController)

LeftMenuViewController (UIViewController)

I am using InitView to set my FirstView as a top view.

My FirstView has a button that when clicked, SecondView displays a top view.

Is it possible to revive a changing view from above, as if I are opening a new view? or how can I open a new view that uses ECSliding as the first?

I use this code to change topview:

self.slidingViewController.topViewController = second; [self.slidingViewController resetTopView]; 

The animation I want can only be by default:

 [self presentViewController:(*UIViewController) animated:YES completion:nil]; 
+4
source share
5 answers

Subclass of ECSlidingViewController. I call my subclass DeckController:

In DeckController.h:

 - (void)setTopViewController:(UIViewController *)topViewController withTransition:(CATransition*)transition; 

In DeckController.m:

 - (void)setTopViewController:(UIViewController *)topViewController withTransition:(CATransition*)transition { self.topViewController = topViewController; [UIView animateWithDuration:0.25f animations:^() { [[self.view layer] addAnimation:transition forKey:@"topViewTransition"]; }]; } 

Then, in the view controller that wants to switch to the new top view, do the following:

 CATransition *animation = [CATransition animation]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromRight]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [animation setFillMode:kCAFillModeBoth]; [animation setDuration:.25]; DeckController *deck = (DeckController*)self.slidingViewController; [deck setTopViewController:newTopViewController withTransition:animation]; 
+3
source

Probably your best bet is to use the animation methods of the view controller. Animate the top view from the screen, in the completion block, change the top-level controller (to the second), then start a new animation to enliven the top view on the screen.

 [self.slidingViewController anchorTopViewOffScreenTo:... animations:... onComplete:^{ self.slidingViewController.topViewController = second; [self.slidingViewController resetTopView]; }]; 
0
source

I use the same operation as if I clicked on a menu item in my left menu.

 [self.anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{ CGRect frame = self.topViewController.view.frame; self.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondVC"]; self.topViewController.view.frame = frame; [self resetTopView]; }]; 

Just summarize it and you can call it everywhere. He does the animation himself. You can do it like @Alex, but if you don't need to do any custom animation, that's all you need.

NB. in my Im example using this in the initViewController (for which it is an ECSlidingViewController, so I send it to self ) to force the user to enter a specific viewController. If you need to change the view in any subViewControllers, you simply post to self.slidingViewController , as shown below:

 [self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{ CGRect frame = self.slidingViewController.topViewController.view.frame; self.slidingViewController.topViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"secondVC"]; self.slidingViewController.topViewController.view.frame = frame; [self.slidingViewController resetTopView]; }]; 
0
source

You can manually create the animation and then set topViewController at the end so that the view controller is in the state you are expecting.

 SecondTopViewController *secondTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondTop"]; secondTopViewController.view.frame = self.slidingViewController.view.bounds; secondTopViewController.view.alpha = 0; // temporarily add the second top view so that we can animate it in. [self.slidingViewController.view addSubview:secondTopViewController.view]; [UIView animateWithDuration:0.5 animations:^{ secondTopViewController.view.alpha = 1; } completion:^(BOOL finished) { // remove the second top view. [secondTopViewController.view removeFromSuperview]; // let sliding view controlller take over from here self.slidingViewController.topViewController = secondTopViewController; }]; 

See my working example here: https://github.com/enriquez/ECSlidingViewController/tree/so-16658539

0
source

@ Michael Enriquez’s answer turned into a quick one.

 let viewController = (self.storyboard?.instantiateViewControllerWithIdentifier("ViewController"))! as? ViewController let navController = UINavigationController(rootViewController: viewController!) navController.view.frame = self.slidingViewController().view.bounds navController.view.alpha = 0 self.slidingViewController().view.addSubview(navController.view) UIView.animateWithDuration(0.25, animations: { navController.view.alpha = 1 }, completion: {(finished:Bool) -> Void in navController.view.removeFromSuperview() self.slidingViewController().topViewController = navController }) 
0
source

Source: https://habr.com/ru/post/1481837/


All Articles