iOS 幀動畫之翻轉和旋轉動畫


記錄兩個比較簡單的動畫,一個是翻轉的動畫,一個是旋轉的動畫。

旋轉動畫:

[UIView animateWithDuration:3 animations:^{
        if (formView) {
            formView.transform = CGAffineTransformMakeRotation(M_PI);
        }
    }];

2

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默認是順時針效果,若將fromValue和toValue的值互換,則為逆時針效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue = [NSNumber numberWithFloat: M_PI *2];
    animation.duration = 3;
    animation.autoreverses = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT; //如果這里想設置成一直自旋轉,可以設置為MAXFLOAT,否則設置具體的數值則代表執行多少次
    [formView.layer addAnimation:animation forKey:nil];

 

 翻轉動畫:

1 圍繞中間軸翻轉

[UIView transitionWithView:formView duration:2.0f options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
        
        
    } completion:^(BOOL finished) {
        NSLog(@"圖像翻轉完成");
    }];

 2 翻頁,類似日歷的那種

//開始動畫
    [UIView beginAnimations:@"doflip" context:nil];
    //設置時常
    [UIView setAnimationDuration:1];
    //設置動畫淡入淡出
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //設置代理
    [UIView setAnimationDelegate:self];
    //設置翻轉方向
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:formView cache:YES];
    //動畫結束
    [UIView commitAnimations];

 3 翻頁 往上翻

 [UIView beginAnimations:@"curlUp" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//指定動畫曲線類型,該枚舉是默認的,線性的是勻速的
    //設置動畫時常
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    //設置翻頁的方向
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:formView cache:YES];
    //關閉動畫
    [UIView commitAnimations];

 4 縮放動畫,直接在原來的基礎上進行縮放

    CGAffineTransform transform;
    transform = CGAffineTransformScale(formView.transform,1.2,1.2);
    [UIView beginAnimations:@"scale" context:nil];
    [UIView setAnimationDuration:2];
    [UIView setAnimationDelegate:self];
    [formView setTransform:transform];
    [UIView commitAnimations];

 5


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM