UIView动画

时间:2010-08-13 09:25:12

标签: iphone objective-c cocoa-touch iphone-sdk-3.0

为什么这段代码没有做任何事情?

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

另外,我在哪里可以看到beginAnimations的所有可能参数列表:?

2 个答案:

答案 0 :(得分:6)

您应该在包含更改的视图上设置动画过渡,例如..

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:self.view.superview cache:YES];

此外,转换应该是UIViewAnimationTransition类型的常量。

+beginAnimations:context:方法可以将任何字符串作为其第一个参数,并将任何指针作为其第二个参数。

答案 1 :(得分:0)

使用 QuartzCore.framework 使用这些动画。

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

对于 AnimationType ,您可以使用以下选项: kCATransitionMoveInkCATransitionPushkCATransitionRevealkCATransitionFade

对于 AnimationSubType ,您可以使用以下选项: kCATransitionFromLeftkCATransitionFromRightkCATransitionFromTopkCATransitionFromBottom