Why is this CATransition not working? - iphone

I'm trying to transition the text of a UILabel:
CATransition *animation = [CATransition animation];
animation.duration = 4;
animation.type = kCATransitionReveal;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[label.layer addAnimation:animation forKey:nil];
label.text = resultDateStr;
This works just fine. But when I set it to kCATransitionFade, it stops working. Tested on iOS 4.3 and 5.0 Any idea?

Try this
[CATransaction begin];
CATransition *animation = [CATransition animation];
animation.type = kCATransitionFade;
animation.duration = 3.50;
[self.view addSubview:mySecondUIView]
[[self.view layer] addAnimation:animation forKey:#"Fade"];
[CATransaction commit];

Verify that you perform this task on the main thread.

Related

CATransition for segue animation (pre iOS 7 style)

I have a custom segue, trying to replicate the push/pop segues of the pre iOS 7 style:
viewControllers animating SIDE-BY-SIDE, with NO darkening. (Is it really that hard!)
The code below works, except:
the exiting page becomes dark on exit
the entering page is dark on entering (gradually becomes normal as it moves into position)
These images illustrate the problem:
and then...
Is there a way to stop this darkening effect? I would be really grateful for some help.
-(void)perform
{
UIViewController *source = self.sourceViewController;
UIWindow *window = source.view.window;
CATransition *transition = [CATransition animation];
[transition setDuration:2.0];
[transition setDelegate:self];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
[transition setType:#"push"];
[transition setSubtype:kCATransitionFromRight];
[window.layer addAnimation:transition forKey:kCATransition];
[window setRootViewController:self.destinationViewController];
}
These 2 functions work fine for me, although the code is pretty similar to yours, I hope it helps.
+(void) modalRight:(UIViewController*)vc destvc:(UIViewController*)viewCtrl{
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[vc.view.window.layer addAnimation:transition forKey:nil];
[vc presentModalViewController:viewCtrl animated:NO];
}
+(void) modalLeft:(UIViewController*)vc{
CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[vc.view.window.layer addAnimation:transition forKey:nil];
[vc dismissModalViewControllerAnimated:NO];
}

How to move the uiview part of the screen from right to left using CATransition

I am developing one application.In that i want to move the uiview from right to left using below code.
-(void)centerAnimation1:(id)sender
{
theview=qstnview;
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[animation setanima]
[[theWindow layer] addAnimation:animation forKey:#"SwitchToView1"];
[[theview layer] addAnimation:animation forKey:#"SwitchToView1"];
[qstnview removeFromSuperview];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if(animate)
{
CATransition *animation = [CATransition animation];
animation.delegate = self;
[animation setDuration:0.4];
[animation setType:kCATransitionMoveIn];
if(rhtolft)
{
[animation setSubtype:kCATransitionFromLeft];
rhtolft=NO;
}
else
{
[animation setSubtype:kCATransitionFromRight];
}
//[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
//[animation setanima]
[[theview layer] addAnimation:animation forKey:#"SwitchToView1"];
[self.view addSubview:qstnview];
}
}
But this one is moving the view from right side last edge to left side.But i need to move within the frame size only.I dont need to start from right side edge.So please tell me how to do that one.
EDIT:
[UIView animateWithDuration:0.33f
delay:0.0f
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction
animations:^{
[theView setFrame:newFrame]; //set new frame for view where x =200;
}
completion:^(BOOL finished){
// do whatever post processing you want (such as resetting what is "current" and what is "next")
}];
The screen from right to left using CATransition like this
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theView layer] addAnimation:animation forKey:#"rightToLeftAnimation"];
Use this code for changing images with animation:
CATransition *transition = [CATransition animation];
transition.duration = 1.0f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype=kCATransitionFromLeft;
[yourImageViewName.layer addAnimation:transition forKey:nil];
I dont think you need to dive down to CA to do this kind of thing. It can be done using UIView animations. Here http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial is a good tutorial on UIView animations.

troubles with animation

I have a little problem, I have a viewcontroller with a webview and some button, I want to apply to webview a curl animation and see instad webview the view if the same controller.
like this
instead this
in the first case I use webview.hidden = YES but when I try to came back the view is (obviusly) hidde, if I put webview.hidden = NO on the method for come back I get this
any solution?
this is my code:
- (IBAction)toggleView:(id)sender {
CATransition *animation = [CATransition animation];
[animation setDelegate:self.view];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.7;
[animation setRemovedOnCompletion:NO];
[[self.vistaWeb layer] addAnimation:animation forKey:#"pageCurlAnimation"];
}
- (IBAction) torna {
CATransition *animation = [CATransition animation];
[animation setDelegate:self.view];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeBackwards;
animation.startProgress = 0.7;
animation.endProgress = 0;
[animation setRemovedOnCompletion:NO];
[[self.vistaWeb layer] addAnimation:animation forKey:#"pageCurlAnimation"];
}

CATransition page curl from top

I wanted to know if anyone managed a pagecurl from the top using the CATRANSITION. I have the following :
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.30;
[animation setRemovedOnCompletion:NO];
[self.view.layer addAnimation:animation forKey:#"pageCurlAnimation"];
but unfortunately, it always does the page curl from the bottom. I will be very grateful if anyone can tell me how to do a page curl from the top.
Many thanks.
I've got this working. You need to set animation.type = #"pageUnCurl"; - who would have thought! Thanks apple.
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
animation.type = #"pageUnCurl";
animation.subtype = kCATransitionFromTop;
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.3;
[animation setRemovedOnCompletion:NO];
[self.helpView.layer addAnimation:animation forKey:#"pageCurlAnimation"];
Found the answer, need to set subtype to from right!
subtype = KCATransitionFromLeft or KCATransitionFromRight
you can also remove the animation.endProgress if you want a total animation of curl page .
=)

FlipFromRight UIView animation

First here's my code:
[_helperView addSubview:_navigationController.view];
[_helperView addSubview:itemView];
[UIView beginAnimations:#"pageFlipAnimation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:_helperView cache:NO];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(pageFlipAnimationDidStop)];
[itemView removeFromSuperview];
[UIView commitAnimations];
My problem with this that nothing is animated. If I add the _navigationController.view and itemView before (I mean not in this method) everything is ok, but when I add before the animation it does nothing. I also tried to call again the animation in the animation didStopSelector and also works there.
Can you help me please why it doesn't want to work in this case? Any suggestions how to resolve it?
You should probably give the UI the chance to effectuate the addition of itemView. To do this, add a line after addSubview:itemView:
[self performSelector(removeAnim:) withObject:itemView afterDelay:0.01];
and move the animation block to a function
-(void)removeAnim:(UIVieW*)itemView
This should fix the problem.
Use QuartzCore.framework With these animations.
-(void)viewSlideInFromRightToLeft:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromRight;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromLeftToRight:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromLeft;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromTopToBottom:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromBottom ;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
-(void)viewSlideInFromBottomToTop:(UIView *)views
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.5;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromTop ;
transition.delegate = self;
[views.layer addAnimation:transition forKey:nil];
}
For AnimationType you can use following option:-> kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade
For AnimationSubType you can use following option:-> kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom