transitionFromView with UIViewAnimationOptions similar like navigating with UINavigationController - ios

I'm using a similar approach described here for the animation from one view controller to another:
UIWindow *window = (UIWindow *)[[UIApplication sharedApplication].windows firstObject];
[UIView transitionFromView:window.rootViewController.view
toView:vc.view
duration:0.65f
options:UIViewAnimationOptionTransitionCrossDissolve // transition animation
completion:^(BOOL finished){
window.rootViewController = vc;
}];
Looking into the UIViewAnimationOptions I didn't found an option for the default animation, which occurs when doing the same with UINavigationController.
Is it possible to get the same animation behavior (moving the view left)? How?
I tried it with this animation:
[UIView animateWithDuration:0.65 animations:^{
view.transform = CGAffineTransformMakeTranslation(-view.frame.size.width, 0);
} completion:^(BOOL finished) {
// do something
}];
but while translating to the new view the background is completely black instead of bringing the other view controller in.

Now I'm doing it in a different way. I start with my navigation controller and its root view. Then I push another view controller on the stack. In viewDidAppear of this new view controller I'm removing the first view controller from the navigation stack. One downside: You can see the back button for a short time.
The animation solution I tried will need the other view controller animated in. Also I had problems with views which very not layout correctly (because of edgesForExtendedLayout).

Related

When i switch View In TabBarController the ScrollView Stop Scroll,How to Solve it?

in Controller A: here the Code:
[UIView animateWithDuration:5 animations:^{
[self.awardScrollView setContentOffset:CGPointMake(self.awardScrollView.frame.size.width * 19, 0)];
} completion:^(BOOL finished) {
isFinished = YES;
}];
i set 5s to finish the animation,but i switch controller to B with TabBarController,i found the animation is stop in Controller A.How can i let the ScrollView continue Scroll Background in Controller A even i Switch to Controller B?
Core Animation won't animate a view that's not in the on-screen view hierarchy. When a view is removed from the on-screen view hierarchy, Core Animation removes all animations from the view.
You can add another animation when the view comes back on screen if you want.

Keyframe animation takes long time to start after UIView animateWithDuration is called

I am using the following method to chain animations:
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^(){
// Animations here
}
completion:^(BOOL finished) {
if (finished) {
// Chained animation
}
}];
These animations play whenever I present and dismiss a view controller, call it View Controller 1.
When I load a second view controller, View Controller 2, I display an interstitial loading view on top of mainWindow, where mainWindow is
UIWindow *mainWindow = [[[UIApplication sharedApplication] delegate] window];
This interstitial loading view shows a spinner that is animated using a keyframe animation.
The problem I am running into is that if I load View Controller 1 multiple times (say 5+ times), then load View Controller 2, the spinner animation begins to take a long time to start. After entering View Controller 1 several more times, then entering View Controller 2, View Controller 2's animation takes so long to begin that the loading view is removed before the spinner ever gets a chance to start animating.
Does anyone know what might be causing this behavior? Does it have anything to do with UIView animations not being properly removed when I leave View Controller 1?
Call the method in the main_queue , this solved my problem.
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^(){
// Animations here
}
completion:^(BOOL finished) {
if (finished) {
// Chained animation
}
}];
});

How to animate image in tableview to extend and open another view controller simultaneously?

I'm making a messenger app and I want the user to click on image in my tableview and it should extend to full screen and show different controls on navigation bar.
How do I go about it?
I thought I can take the same image, put UIImageView on top of original cell image and animate it to full screen. But how do I go about presenting different controller without blinks, delays, and animations?
This is done in many messaging applications.
Use a custom transition, to extend the image view from the initial preview size to full screen. When called, return a transition delegate from transitioningDelegate, which in turn should return an animation controller from animationControllerForPresentedController:presentingController:sourceController:. This animation controller will be responsible for the animation that will be performed when presentViewController:animated:completion: is called.
In your animation controller, implement and in it, create the animation:
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
MyChatViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
[[transitionContext containerView] addSubview:toViewController.view];
toViewController.view.frame = [transitionContext.containerView convertRect:fromViewController.imageViewToTransitionFrom.frame fromView:fromViewController.imageViewToTransitionFrom];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController];
} completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}
Here, MyChatViewController is your chat view controller and imageViewToTransitionFrom holds the image view you wish to transition from.
If you need to push a view controller instead of present it (like WhatsApp does it), there are analogous methods to perform the custom push animation.
You can perform a dismiss/pop animation in a similar manner, or use the default system one.
Read here about custom view controller transitions in iOS7.

How to bounce child view controller's UICollectionView when the child view controller is presented?

I want to present a child view controller by dropping it from top to the bottom. The child view controller is a UICollectionViewController with several cells in it. I can use the iOS7 UIViewControllerContextTransitioning for the dropping down view controller transition. But if I want only the collection view to bounce (like a ball hit on the ground) when the child view controller is presented, how should I do?
I have try to use UIKit Dynamics and create some UIAnimatorBehavior on the UICollectionView after the transition, like UIGravityBehavior and UIPushBehavior. But they don't seem to work. Maybe I am using them in the wrong way. Is there anyone can give me some hints?
Update
After tried several solutions, I finally came out a solution which is pretty close to what I want. This video shows the result: http://youtu.be/tueXDBMsdt0
But I think there should be a better solution for that. And here is my solution's steps:
Create a UIViewControllerAnimatedTransitioning object, which animate the view controller transition from top to bottom.
The child view controller is a UICollectionViewController. At the end of transition animation, I set child view controller's scrollview content offset to (0, -30), and then complete the transition.
In child view controller's viewDidAppear, animate the content offset back to (0, 0).
Besides, I also follow the instructions in the article: http://www.teehanlax.com/blog/implementing-a-bouncy-uicollectionviewlayout-with-uikit-dynamics/ to set UIKit dynamics animator in cells. When the content offset is changed, then the cells will look like bouncing.
The transition animation code looks like this:
- (void) animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
CGRect frame = [[transitionContext containerView] frame];
CGRect startFrame = frame;
startFrame.origin.y -= CGRectGetHeight(transitionContext.containerView.frame);
[transitionContext.containerView addSubview:fromViewController.view];
[transitionContext.containerView addSubview:toViewController.view];
toViewController.view.frame = startFrame;
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
toViewController.view.frame = frame;
}
completion:^(BOOL finished) {
((UICollectionViewController*)toViewController).contentOffset = CGPointMake(0, -30);
[transitionContext completeTransition:YES];
}];
}
And in child view controller viewDidAppear:
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
}
But I would still want the cell to bounce more naturally. Any other better solutions?
Important: this can now be done in iOS in one simple line of code:
https://stackoverflow.com/a/23514653/294884
Detailed answer when fuller control is needed:
If you want the same effect between the Screen lock and the Camera on the iPhone, you can use UIViewControllerContextTransitioning
There are a good tutorial here http://www.objc.io/issue-5/view-controller-transitions.html
and here http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
if you have a Apple developer account, there are a video about View controller transition : https://developer.apple.com/tech-talks/videos/
The video is named "Architecting Modern Apps, Part 1"
This way work only on iOS7!

View drawn under status bar

So i managed to load another view when someone presses a button ,but it loads it to high. `i don't know why this happens. The difference is exactly the top bar hight. This is my code:
In the delegate i have:
- (void)flipToAbout {
AboutViewController *aaboutView = [[AboutViewController alloc] initWithNibName:#"AboutViewController" bundle:nil];
[self setAboutController:aaboutView];
[aaboutView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES];
[homeController.view removeFromSuperview];
[self.window addSubview:[aboutController view]];
[UIView commitAnimations];}
In the about view i didn't change anything.Please tell me what is the problemm .Thanks.
The problem is that you're adding your view directly to the window without accounting for the navigation bar. Normally, if you have a navigation bar, you use a navigation controller to manage your view controllers. Pushing a view controller onto the nav controller's stack causes the nav controller to add that view controller's view to the window for you, and you don't have to worry about the nav bar. Since you're doing it by hand, though, you'll want to reposition the view after you add it to the window.
Note that this problem doesn't have anything to do with nibs except that you load your view from a nib. The same thing would happen if you created the view programmatically.

Resources