FlipFromRight UIView animation - iphone

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

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];
}

CATransition animation gets crashed sometimes

I am using a CATransition animation in my application and it works fine, but crashes some times.
This is my Code:
-(void)_close_btn_click:(UIButton*)button
{
NSLog(#"update Button %ld clicked.",(long int)[button tag]);
NSInteger intvalue=[[NSString stringWithFormat:#"%ld",(long int)[button tag]]intValue];
NSLog(#"delete_index:%d",intvalue);
CATransition* transition = [CATransition animation];
[transition setDuration:1.0];
transition.type = #"rippleEffect";
transition.subtype = kCATransitionFromLeft;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[cell._slide_view.layer addAnimation:transition forKey:#"push-transition"];
CATransition* transition1 = [CATransition animation];
[transition1 setDuration:1.0];
transition1.type = #"rippleEffect";
transition1.subtype = kCATransitionFromLeft;
[cell._en_cell_close_btn.layer addAnimation:transition forKey:#"push-transition"];
cell._slide_view.hidden=YES;
}
I guess maybe your cell or _slide_view has been deallocated before you call this method

Why is this CATransition not working?

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.

switch two view controller's view in a cube animation

the code below implement the switch between two view in a cube animation .
UIViewController* viewCtrl = [[UIViewController alloc] init:book];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube";
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
but, if the view don't belong to self.navigationController, how to do switch in cube animation between two view controller, and then how to scale the current view controller's view in the same time? thanks very much
This worked for me:
-(IBAction)animate:(id)sender {
NSLog(#"animate");
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 0.8;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[0];
transition.subtype = subtypes[1];
[self.view.layer addAnimation:transition forKey:nil];
SecondView *_secondViewController = [[SecondView alloc]initWithNibName:#"secondView" bundle:nil];
self.secondViewController = _secondViewController;
_secondViewController = nil;
[[[self view] layer] addAnimation: transition forKey: nil];
[[self view] addSubview: [self.secondViewController view]];
}
-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
[self.view release];
}

UIView Animations

Why doesn't this code do anything?
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationCurveEaseIn forView:self.view cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
Also, where can I see all the list of possible arguments for beginAnimations:?
You should set the animation transition on the view containing the change, e.g..
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view.superview cache:YES];
Also, the transition should be a constant of type UIViewAnimationTransition.
The +beginAnimations:context: method can take any string as its 1st argument, and any pointer as its 2nd argument.
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 options:
kCATransitionMoveIn,
kCATransitionPush,
kCATransitionReveal,
kCATransitionFade.
For AnimationSubType you can use following options:
kCATransitionFromLeft,
kCATransitionFromRight,
kCATransitionFromTop,
kCATransitionFromBottom.