How can I use CATransition to move from one controller to the next so that the view moves up to show the second window. I want the view from controller 1 to move up and show the view from the second controller. How can I do that?
Here's what I am doing?
CATransition *transition = [CATransition animation];
transition.duration = 0.7f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:destinationController animated: NO];
try this one
CATransition* transition = [CATransition animation];
transition.duration = 0.7f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn,kCATransitionReveal, kCATransitionFade, kCATransitionPush,
//transition.subtype = kCATransitionFromTop; //kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromLeft, kCATransitionFromBottom
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[[self navigationController] popViewControllerAnimated:NO];
Related
I want a transition like this.
Custom Transition
You can customize your transition using CATransition
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 0.25f;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[YourView.view.layer addAnimation:animation forKey:#"animation"];
[self.view addSubview:bView];
I'm changing layouts when selecting a cell in a uicollectionview and have added a custom animation to the collectionview layer
currently I'm using this code:
[self.collectionView performBatchUpdates:^{
CATransition *transition = [CATransition animation];
transition.duration = 0.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
[self.collectionView.layer addAnimation:transition forKey:nil];
[self.collectionView setCollectionViewLayout:self.horizontalPagingLayout animated:NO];
self.galleryInHorizontalScrollMode = YES;
[self.collectionView setPagingEnabled:YES];
} completion:^(BOOL finished) {
[self reloadData];
}];
I would like to change the animation style (transition.type) such that the selected cell will "grow" (or shrink) to the size of the final cell size defined in the collectionview layout
How can this be done?
I've tried solutions as suggested here but they looked very poor
I'm trying stop the animation on my UIActivityIndicatorView in the same method that I push a view controller using a CATransition fade.
Instead of stopping the animation, then fading to the next view controller, the UIActivityIndicatorView contiues animating throughout the entire fade, no matter how long I set the duration.
Any ideas how I can get the spinning to stop, then push/fade in the same method?
- (void)pushView:(NSNotification *)notification {
[self.activityIndicator stopAnimating];
NextViewController* nextViewController = [[NextViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:nextViewController animated:NO];
}
Edit 1
Along the same lines as David's answer, I was able to successfully stopAnimating if I used dispatch_after and delayed for a fraction of a second. Is there a better way to accomplish this?:
- (void)pushView:(NSNotification *)notification {
[self.activityIndicator stopAnimating];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.0001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
NextViewController* nextViewController = [[NextViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:nextViewController animated:NO];
});
}
I've run into something similar to this before. What you are running is called Synchronous Execution. In synchronous execution, the UI is not updated until the compiler terminates the function, a.k.a. the }. How do you get around this? Simple. Just run any methods to update the UI in an Asynchronous dispatch:
- (void)pushView:(NSNotification *)notification {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
dispatch_async(dispatch_get_main_queue(), ^(void){
[self.activityIndicator stopAnimating];
});
NextViewController* nextViewController = [[NextViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1.5f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:nextViewController animated:NO];
});
}
Whoops! I forgot to put the other code in a plain dispatch! Try the edited code and it should work!
This way the [self.activityIndicator stopAnimating]; is run on a priority thread, while the rest of the code in the function is run in the default priority thread, effectively running the code at the same time, the way you would expect it to.
Cheers!
Many people use this method to add animation on switching views. When I try to add animation effect on adding a subview, the view always flash once。 The reason is that the view add subview immediately at the beginning, after that, the animation starts.
CATransition *transition = [CATransition animation];
transition.duration = 0.35;
transition.removedOnCompletion = NO;
transition.fillMode = kCAFillModeForwards;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
[[animationView layer] addAnimation:transition forKey:#"switchView"];
OtherViewController *otherController = [[OtherViewController alloc]init:cityID];
self.myOtherViewController = otherController;
[otherController release];
[self.view insertSubview:myOtherViewController.view atIndex:1];
What's the reasons of problem? How to implement the animation of loading new view without flash?
After modified fillMode to kCAFillModeBoth, it works.
transition.fillMode = kCAFillModeForwards;
CATransition NOT working when subtype is kCATransitionFromTop.
CALayer *layer = [self.view layer];
CATransition *transition = [CATransition animation];
transition.type = #"pageCurl";
transition.duration = 0.5;
transition.delegate = self;
if(viewMode == PORTRAIT)
[transition setSubtype:kCATransitionFromRight];
else if(viewMode == UPSIDEDOWN)
[transition setSubtype:kCATransitionFromLeft];
else if(viewMode == RIGHT)
[transition setSubtype:kCATransitionFromBottom];
else if(viewMode == LEFT)
[transition setSubtype:kCATransitionFromTop];
[layer addAnimation:transition forKey:nil];
everything works fine except kCATransitionFromTop. (comes from bottom)
I think subtype of #"pageCurl" can't be FromTop, so the default value (FromBottom)
is assigned. Am I right? and is there anyway to fix this?