node ninja
node ninja

Reputation: 33036

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:?

Upvotes: 0

Views: 907

Answers (2)

Vaibhav Sharma
Vaibhav Sharma

Reputation: 1123

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.

Upvotes: 0

kennytm
kennytm

Reputation: 523674

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.

Upvotes: 6

Related Questions