- (IBAction)image:(id)sender {
    [UIView beginAnimations:@"xuanzhuan" context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.myimage cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    if (self.myimage.image==[UIImage imageNamed:@"0.png"]) {
        [self.myimage setImage:[UIImage imageNamed:@"1413009041819.png"]];
    }
    else
        [self.myimage setImage:[UIImage imageNamed:@"0.png"]];
    [UIView commitAnimations];
}
- (IBAction)controller:(id)sender {//可以用到controller的切换
    CATransition *anima=[CATransition animation];//也可以使用alloc初始化
    [anima setDuration:1];
    [anima setType:kCATransitionMoveIn];//这个暂时不知道什么效果,去掉不可以
    [anima setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [self.view.layer addAnimation:anima forKey:kCATransitionReveal];
}
- (IBAction)qiehuan:(id)sender {
    CATransition *anima=[[CATransition alloc]init];
    [anima setDuration:1];
    //[anima setType:kCATransitionFromRight];
    if (self.myimage.image==[UIImage imageNamed:@"0.png"]) {
        [self.myimage setImage:[UIImage imageNamed:@"1413009041819.png"]];
    }
    else
        [self.myimage setImage:[UIImage imageNamed:@"0.png"]];
    [anima setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [self.myimage.layer addAnimation:anima forKey:kCATransitionPush];
}


CATransition方法给你更多的控制设置,因此更多的事情,例如。定时功能。作为一个对象,您可以将它存储为后,重构点所有动画,以减少重复代码,等等。
UIView类方法是方便的方法常见的动画,但比CATransition更有限。例如,只有四种可能的过渡类型(翻转,翻转,蜷缩,旋度)。如果你想做一个淡入,要么你不得不掏腰包CATransition褪色的过渡,或者建立一个明确动画UIView的alpha。
注意CATransition在Mac OS X将允许您指定一个任意CoreImage过滤器作为过渡,但目前iPhone现在你不能这么做,这缺乏CoreImage

CGRect imageFrame = imageView.frame;
imageFrame.origin.y = self.view.bounds.size.height;

[UIView animateWithDuration:0.5
    delay:1.0
    options: UIViewAnimationCurveEaseOut
    animations:^{
        imageView.frame = imageFrame;
    } 
    completion:^(BOOL finished){
        NSLog(@"Done!");
    }];



在使用后者对于很多不错的轻量级的动画。你可以用它淡入淡出两个视图,或消失在前面的另一个,或褪色。你可以拍一个视图在另一个像一个横幅,你可以查看伸展或收缩……我得到很多beginAnimation / commitAnimations里程。

//不仅仅使用
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myview cache:YES];

//还可以使用
[UIView beginAnimations:nil context:NULL]; {
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationDelegate:self];
    if (movingViewIn) {
// after the animation is over, call afterAnimationProceedWithGame
//  to start the game
        [UIView setAnimationDidStopSelector:@selector(afterAnimationProceedWithGame)];

//      [UIView setAnimationRepeatCount:5.0]; // don't forget you can repeat an animation
//      [UIView setAnimationDelay:0.50];
//      [UIView setAnimationRepeatAutoreverses:YES];

        gameView.alpha = 1.0;
        topGameView.alpha = 1.0;
        viewrect1.origin.y = selfrect.size.height - (viewrect1.size.height);
        viewrect2.origin.y = -20;

        topGameView.alpha = 1.0;
    }
    else {
    // call putBackStatusBar after animation to restore the state after this animation
        [UIView setAnimationDidStopSelector:@selector(putBackStatusBar)];
        gameView.alpha = 0.0;
        topGameView.alpha = 0.0;
    }
    [gameView setFrame:viewrect1];
    [topGameView setFrame:viewrect2];

} [UIView commitAnimations];




☟☟可点击下方广告支持一下☟☟

最后修改:1970 年 01 月 01 日
请我喝杯可乐,请随意打赏: ☞已打赏列表