Switching rootViewController with MMDrawerController: weird behaviour of the transition animation - ios

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

Related

iOS8 navigationBar top right corner of the black [duplicate]

I am getting a really strange animation behaviour when pushing another view controller that has the bottom bar hidden with hidesBottomBarWhenPushed. The first thread I found was that: Strange animation on iOS 7 when using hidesBottomBarWhenPushed in app built targeting <= iOS 6 but as my application is only build and run on iOS7 it is not the case for my problem.
Please see the following video that shows the problem (look in the top right corner):
https://dl.dropboxusercontent.com/u/66066789/ios7.mov
This strange animation shadow only occurs when hidesBottomBarWhenPushed is true.
How can I fix that?
Solved my problem:
self.tabBarController.tabBar.hidden=YES;
In the second view controller is the way to go.
Leo Natan is correct. The reason for this blur effect is because the entire Tab Bar Controller is being animated underneath the navigation controller, and behind that view is a black UIWindow by default. I changed the UIWindow background color to white and that fixed the issue.
hidesBottomBarWhenPushed seems to work great with UITabBars (iOS 7/8).
Turn off the Translucent property of Navigation Bar in Storyboard.
In My Case, I had TabBarViewController with UINavigationController in each tabs & faced similar issue. I used,
nextScreen.hidesBottomBarWhenPushed = true
pushViewToCentralNavigationController(nextScreen)
It works fine when nextScreen is UITableViewController subclass & applied auto layout. But, It does not work fine when nextScreen is UIViewController. I found it depends on nextScreen auto layout constraints.
So I just updated my currentScreen with this code -
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.tabBar.hidden = true
}
For more details - https://stackoverflow.com/a/39145355/2564720
An elegant way of doing this, while keeping transparency, is to add this to the root UIViewController:
- (void)viewWillAppear:(BOOL)animated {
[UIView animateWithDuration:0.35f animations:^{
self.tabBarController.tabBar.alpha = 1.0f;
}];
}
- (void)viewWillDisappear:(BOOL)animated {
[UIView animateWithDuration:0.35f animations:^{
self.tabBarController.tabBar.alpha = 0.0f;
}];
}
This way you'll get a nice fade-in/fade-out animation of the tab bar.
What if in the second view controller in viewWillAppear you put
[self.navigationController setToolbarHidden:YES animated:NO];

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.

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.

UIScrollView Jerky Scrolling

I have a big scroll view. I just wish to scroll around the scroll view with fixed steps on every button press. However when I write the following code the scroll view scrolling is very jaggy. Can someone explain why?
CGPoint lstructCurrentPoint = self.objScrollView.contentOffset;
lstructCurrentPoint.x += 400;
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,
lstructCurrentPoint.y,
self.objScrollView.bounds.size.width,
self.objScrollView.bounds.size.height)
animated:NO];
} completion:^(BOOL finished)
{
}];
I do not use the animated:Yes arguement because I need custom scroll speeds between the different contentOffsets.
when you update your scroolview content frame while scrolling with an animation is like you try to update something that is in the past that is already changed... (probably is not the best explanation :D )
try with this in your animation option:
options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionBeginFromCurrentState
Why don't you just try using
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x, lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
instead of using this within UIView animation function.
Try to use
[self.objScrollView setContentOffset: CGPointMame(lstructCurrentPoint.x, lstructCurrentPoint.y) animated: YES];
instead of scrollRectToVisible.
scrollRectToVisible animated is an animation by itself.
With your current code, you are trying to animate the animation.
Hence it is jerky.
Just use to scroll the rect to visible:
[self.objScrollView scrollRectToVisible:CGRectMake(lstructCurrentPoint.x,lstructCurrentPoint.y,self.objScrollView.bounds.size.width,self.objScrollView.bounds.size.height) animated:YES];
No one can properly answer your question without knowing what content you have in the scrollView.
However, you can find out what is causing this yourself.
Profile the app on your device. This will open Instruments. Select the Core Animation tool.
When the app is running scroll the view so that instruments captures the data.
Now the Time Profiler section will tell you exactly what is taking a long time. Fix this and you'll have smooth scrolling.

Changing viewcontrollers with smooth push transition and without navigationcontroller

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/

Resources