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

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.

Related

iOS7 slideout drawer draggable bug

I am trying to implement a slideout drawer similar to a the one found in this guide: http://www.raywenderlich.com/32054/how-to-create-a-slide-out-navigation-like-facebook-and-path
I have two subviews that are added to the navigation controller, The drawer is initialized as follows in viewDidLoad:
self.drawerViewController = [[DrawerViewController alloc] initWithNibName:#"drawer" bundle:nil];
self.drawerViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.drawerViewController.view];
[self addChildViewController: self.drawerViewController];
[self.drawerViewController didMoveToParentViewController:self];
self.drawerViewController.view.frame = CGRectMake(0, 0, 150, self.view.frame.size.height);
then the contentview is initialized using a viewcontroller from my storyboard (and i call send subviewtoback to move the drawer behind it):
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.contentViewController = [sb instantiateViewControllerWithIdentifier:#"HomeViewController"];
[self.view sendSubviewToBack:self.drawerViewController.view];
[self pushViewController:self.contentViewController animated:YES];
I move the main content view by animating the frame of the contentview which uncovers the drawer underneath:
[UIView animateWithDuration:SLIDE_TIME delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{self.contentViewController.view.frame = CGRectMake(150, 0, self.view.frame.size.width, self.view.frame.size.height);
}completion:nil];
Which works but if I do something like click the margin of the drawer and drag, the drawer can end up covering the entire screen in the iphone simulator or disappearing showing the black background (which is more easily reproduced when rotating the device while showing drawer). My question is why is the drawerview draggable and how do you prevent this?
Edit:
I have found the source of the dragging is from this addChildViewController line:
[self addChildViewController: self.drawerViewController];
However removing this doesnt allow users to click the table cells anymore.
The problem was using a navigation controller as a container of subviews. I don't think it's meant to be used this way so I ended up scrapping this and rewriting it with a uiviewcontroller container instead.

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.

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

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/

iOS - CATransition and transitionWithView issues

Whenever I use either CATransition or transitionWithView to "push" one view from the right, there is a brief moment where the view that's getting pushed in fades in from black (or whatever the background color is), and the view that's getting pushed away fades out to black.
This might be the intended effect, but it looks messy on my app, and was wondering if anyone knows of a way to prevent this "fade out/in" effect?
Here is the CATransition code I am using to present the new view:
myView = [[MyView alloc] initWithNibName:#"MyView" bundle:nil];
[myView setDelegate:self];
[[mainView layer] addAnimation:pushRightTransition forKey:nil];
// Add the view:
[mainView addSubview:[myView view]];

Resources