Changing viewcontrollers with smooth push transition and without navigationcontroller - ios

I'm trying to change from viewcontroller view1 to viewcontroller view2 with a smooth and nice transition, where view1 gets pushed to the left by view2 within a second. I have made a simple illustration of what I want in my iPhone app.
--> --> -->
I am using storyboard and developing for iOS 6 and higher. I'm not using segues. Currently I'm using this code to change from view1 to view2 without any animations in Xcode:
SecondViewController *viewTwo = [self.storyboard instantiateViewControllerWithIdentifier:#"View2"];
[self presentViewController:viewTwo animated:NO completion:nil];
I am looking for code that can replace my existing code with. Code that changes from view1 to view2 with the push transition
NOTE: I am not using NavigationControllers! Just normal ViewControllers. I would prefer to do this with codes.
EDIT: I understand that this would be very easy to do if I used a navigation controller, but the problem is that I'm done building the storyboard and I have already buildt everything using normal view controller. And that creates my second question:
Are there any way I can simply convert my UIViewControllers to work as UINavigationControllers. Without having to delete my UIViewController and build it again only using UINavController?
ANSWER: I solved my problem by implementing a navigation controller to my project. I have totally misunderstood the whole concept of navigations controllers earlier, but I have now figured it out. So my problem is solved!

Set animation for the view2. Use this code.
-(void)ViewNavigationOnLeftTabs
{
self.view.frame=CGRectMake(420, 0,self.view.frame.size.width,self.view.frame.size.height);
[UIView beginAnimations:#"Anim2" context:nil];
[UIView setAnimationDuration:0.4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDelegate:self];
self.view.frame=CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height);
[UIView commitAnimations];
}
-(IBAction)nextView
{
SecondViewController *sampleV=[[SecondViewController alloc] init];
[self.view addSubview:sampleV.view];
[self ViewNavigationOnLeftTabs];
}
Here I have added transition effect for the secondViewController exactly like your requirement. You need to handle the background view(view1) during the animation.
I have used this code in my app, and it's working fine for me.

Consider using container view controllers. Here is a tutorial:
http://www.cocoanetics.com/2012/04/containing-viewcontrollers/

Related

Autolayout - Compressing UINavigationController at the same time as pushing a new view controller

I am working on an iOS app. The root view controller contains a UINavigationController which wraps up the main contents of the app, and a footerViewController (audio player) that will compress the main content when it animates up into view.
I’m using auto layout to show and hide this footer like so:
_footerVisibleConstraints = [… #“V:|[navControllerView][footerView(==90)]|" …];
_footerHiddenConstraints = [… #“V:|[navControllerView][footerView(==0)]|" …];
Generally this works well. But I’m struggling with one issue. I have a situation where I need to push a new view on the UINavigationController stack and animate my footer into view the same time:
[self.view layoutIfNeeded];
[UIView animateWithDuration:1.5f animations:^{
[[self view] removeConstraints:_footerHiddenConstraints];
[[self view] addConstraints:_footVisibleConstraints];
[[self view] layoutIfNeeded];
}];
[navigationController pushViewController:newViewController animated:YES];
The problem in this situation is that newViewController is animating in snapped to it's final (compressed) state, and not beginning from the full starting height of the view. So there is a gap at the bottom while the footer animates in.
I’ve slowed down the animation and posted a video here to demonstrate what I am describing.
Also, notice how when I pop back to the root view controller the content in the UINavigationController isn’t compressed either.
So, can someone explain to me what’s going on here? Is there a way to accomplish what I am after?
Just add a variable to the .h of your VC to stipulate whether the footer needs to open or not. Then add the footer animation to the didAppear method with a check on the variable. This will result in performing the actions in the order you want them to happen.
If you want both animations to happen at the same time you will need to subclass a segue and add a custom animation.

Custom iOS navigation controller animation : is this wrong?

I've been asked to add a fully custom transition between two UIViewControllers and came up with this solution. It works, but I don't know if there's a better / more elegant way to do it.
By fully custom, I mean involving modifying the first view controller subviews (moving them, not only fading or whatever), being able to change the duration, etc.
I'd like to know two things :
Can this be broken up in any way ? Some problem I might have forgotten maybe ?
Do you think this is ugly ? If so, is there a better solution ?
As a few lines of code is better than a thousand words, here is a very simple example to get the idea :
// Considering that self.mainView is a direct subview of self.view
// with exact same bounds, and it contains all the subviews
DCSomeViewController *nextViewController = [DCSomeViewController new];
UIView *nextView = nextViewController.view;
// Add the next view in self.view, below self.mainView
[self.view addSubview:newView];
[self.view sendSubviewToBack:newView];
[UIView animateWithDuration:.75f animations:^{
// Do any animations on self.mainView, as nextView is behind, you can fade, send self.mainView to wherever you want, change its scale...
self.mainView.transform = CGAffineTransformMakeScale(0, 0);
} completion:^(BOOL finished) {
// Push the nextViewController, without animation
[self.navigationController pushViewController:vc animated:NO];
// Restore old
self.backgroundImageView.transform = CGAffineTransformIdentity;
}];
I've double checked a few things that I thought might get wrong :
After the push, the view hierarchy isn't broken, everything looks fine, self.view suffer any changes
When poping, nextView isn't in self.view any more.
Thanks for your opinions.
There are differents way to make a transition between ViewControllers. Your code works but you can implement a more official way.
Use methode transitionFromViewController:toViewController:
Check the tutorial : http://www.objc.io/issue-1/containment-view-controller.html#transitions
Or you can use UIViewControllerContextTransitioning Check the tutorials : http://www.objc.io/issue-5/view-controller-transitions.html and http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/

uiviewanimation works in ios 7 but gets clipped and offset in ios6

working on moving my app to IOS7, but i'm having a uiviewanimation problem.
Everything works fine in IOS7, but when i use uiviewanimation to "flip" between two views, the view looks wrong during the transition, but fine after. It's higher up, and a part of the bottom of the view is clipped. See attached picture.
When the animation completes, the view "jumps" down to its correct position. I'm at a loss...
the code i use to flip my view is:
newView = [[LocationCrudViewController alloc] initWithNibName:THE_VIEW bundle:nil];
.....
[UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^ { self.window.rootViewController = newView; }
completion:nil];
Point worth noting - i used to do:
self.window addSubview:currentViewController.view];
as the view animation, and that worked, however i then got the warning message that Application windows are expected to have a root view controller at the end of application launch so i switched to the above code which, again, works fine in IOS7.
I'm reeeaaally hoping someone can help out here.
For those interested, here's what i ended up doing:
My views are defined as per normal (for me), no ios6/7 deltas are needed, in a nib with associated controllers.
I have created a "dummy" view, which takes up the entire screen but has no content.
In my application delegate, i create my dummy view and set it as root:
self.root = [[RootViewController alloc] initWithNibName:ROOT_VIEW_CONTROLLER bundle:nil];
self.window.rootViewController = root;
I can then add and remove subviews as i see fit, like this:
[currentViewController.view removeFromSuperview];
UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^ {
[self.window addSubview:newViewController.view]; }
completion:nil];
This works great, and it makes my views go under the status bar in both IOS6 and IOS7, just as i want.
Hope this helps somebody.

Switching rootViewController with MMDrawerController: weird behaviour of the transition animation

I'm switching the rootViewController of the AppDelegate's window at some point of the app lifecycle. I'm trying to animate such switch this way:
[UIView transitionFromView:self.window.rootViewController.view
toView:self.otherViewController.view
duration:0.65f
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){
self.window.rootViewController = self.otherViewController;
}];
Animation is performed but it looks like the second view's height does not fill the screen height, and it suddenly fits the whole screen height once the animation has finished. I hope I've explained properly... what could be happening?
Thanks
EDIT: I've noticed this behavior appears when self.otherViewController.view is a MMDrawerController. I tested the code transitioning from a UINavigationController to another UINavigationController and nothing strange is shown... Has anybody experienced this?
We may have come up with a solution here:
https://github.com/mutualmobile/MMDrawerController/issues/48

Selecting second tab stops animation in first tab and does not restart

I create a new tabbed application project in Xcode 4.2 using Storyboards.
In viewDidLoad, I add the following code:
[UIView animateWithDuration:30
delay:0
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^(void) {
CGRect imageViewFrame = self.scrollingImageView.frame;
imageViewFrame.origin.x = CGRectGetWidth(imageViewFrame) / -2;
self.scrollingImageView.frame = imageViewFrame;
} completion:nil];
Then I create the associated UIImageView property and wire it up in IB.
#property (nonatomic, strong) IBOutlet UIImageView *scrollingImageView;
I put an image into the imageview, run it in the simulator or my iPod Touch, and I see scrolling.
However, when I select the second tab and then go back to the first tab, the animation completes what appears to be immediately and I cannot get it to restart, even if I put the above into viewWillAppear. I have searched through lots of answers and cannot solve it.
Any help would be appreciated.
It appears that the issue you are dealing with is specific to tabbed bar controllers, not storyboards or the specific animation. The issue is that when you switch to a different tab, the animation stops, and when you return to the first tab, it doesn't resume.
Ordering the animation again in viewWillAppear does not work (as you mentioned), but if you first remove the animation in viewWillDisappear, then ordering it again in viewWillAppear should work. For example
- (void)viewWillDisappear:(BOOL)animated
{
[self.view.layer removeAllAnimations]; // or whatever you need to use to remove your specific animation
}
NB: The animation removal code should be in viewWillDisappear rather than in viewWillUnload, since viewWillUnload does not get called when you switch tabs.

Resources