UI Animation 動畫效果

Animation的基本實現功能:
首先創建一個簡單的button 在button方法中來實現不同的動畫效果:
- (void)buttonClicked:(UIButton *)button
{
    // UIView 動畫
    // 1.最簡單的動畫實現
    // 參數1:動畫執行一次需要的時間
    // 參數2:動畫執行的內容(寫動畫執行的結果)
//    [UIView animateWithDuration:10.0 animations:^{
//        button.alpha = 0.38;
//        button.backgroundColor = [UIColor blueColor];
//        button.frame = CGRectMake(0, 0, 320, 100);
//    }];
    
    
    
    
    // 參數3:動畫執行結束後 要執行的代碼
//    [UIView animateWithDuration:1.f animations:^{
//        
//        // 對動畫本身設置
//        
//        // 可以給動畫一個還原效果
//        [UIView setAnimationRepeatAutoreverses:YES];
//        // 動畫重複的次數
//        [UIView setAnimationRepeatCount:1.25];
//        // 動畫延遲幾秒執行
//       // [UIView setAnimationDelay:1.0];
//        // 動畫運行的速度曲線
//        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//        
//        button.backgroundColor = [UIColor blueColor];
//        button.bounds = CGRectMake(0, 0, 200, 200);
//    } completion:^(BOOL finished) {
//        NSLog(@"動畫完畢");
//    }];
    
    
    
    // 3.
    
    // 參數3:動畫的選項 在這裏一般寫 速度曲線
//    [UIView animateKeyframesWithDuration:1.f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
//        button.frame = CGRectMake(0, 0, 200, 200);
//    } completion:nil];
    
    
    
    //4.
    
//    [UIView animateWithDuration:1.f delay:0 usingSpringWithDamping:0.05 initialSpringVelocity:0.4 options:UIViewAnimationOptionCurveEaseIn animations:^{
//        button.frame = CGRectMake(0, 0, 200, 200);
//    } completion:nil];

    
    
    // transition動畫
    
//    [UIView transitionWithView:button duration:1.f options:UIViewAnimationOptionTransitionCurlDown animations:^{
//        button.frame = CGRectMake(0, 0, 200, 200);
//    } completion:nil];
    
    
    
    // 把第一個視圖移除 把第二個視圖 添加到父視圖上
    
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
//    view.backgroundColor = [UIColor blueColor];
//    // 參數1;要移除的view
//    // 參數2:要添加的view
//    [UIView transitionFromView:button toView:view duration:1.f options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
//    
//    }];
    
    
    
    // CAAnimation layer層動畫
    
    // CAPropertyAnimation 是一個抽象類
    // 1. CABasicAnimation 的使用
    
//    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
//    // 從什麼狀態開始放大
//    animation1.fromValue = [NSNumber numberWithInt:1];
//    // 到什麼狀態結束
//    animation1.toValue = [NSNumber numberWithInt:3];
//    // 動畫執行的時間
//    animation1.duration = 1.f;
//    // 是否有一個恢復
//    animation1.autoreverses = YES;
//    animation1.repeatCount = NSIntegerMax;
//    
//    
//    CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
//    
//    // 從什麼狀態開始放大
//    animation2.fromValue = [NSNumber numberWithInt:1];
//    // 到什麼狀態結束
//    animation2.toValue = [NSNumber numberWithInt:M_PI * 2];
//    // 動畫執行的時間
//    animation2.duration = 2.f;
//    // 是否有一個恢復
////    animation2.autoreverses = YES;
//    animation2.repeatCount = NSIntegerMax;
//    
//    
//    
//    // 組動畫 將幾個動畫組合到一起 同時執行
//    
//    CAAnimationGroup *group = [CAAnimationGroup animation];
//    group.animations = @[animation1,animation2];
//    // 將動畫 添加到組動畫之後 每個動畫自己的設置將失效
//    group.duration = 3.f;
//    group.autoreverses = YES;
//    group.repeatCount = NSIntegerMax;
//    
//    [button.layer addAnimation:group forKey:@"111"];
//    
//    
//    
//    [button.layer addAnimation:animation2 forKey:@"111"];
    
    
    
    
//    // 關鍵幀動畫
//    CAKeyframeAnimation *keyFrameAni = [CAKeyframeAnimation animationWithKeyPath:@"position"];
//    
//    // 產生一個路徑
//    CGMutablePathRef path = CGPathCreateMutable();
//    // 設定一個初始點
//    CGPathMoveToPoint(path, nil, 100, 100);
//    
//    // 添加一個路過的點(添加一條直線的路徑)
//    CGPathAddLineToPoint(path, NULL, 200, 100);
//    CGPathAddLineToPoint(path, NULL, 300, 0);
//    CGPathAddLineToPoint(path, NULL, 10, 200);
//    CGPathAddLineToPoint(path, NULL, 30, 0);
//    CGPathAddLineToPoint(path, NULL, 150, 40);
//    CGPathAddLineToPoint(path, NULL, 300, 0);
//    
//    
//    // 添加一條曲線路徑
//    CGPathAddCurveToPoint(path, NULL, 10, 20, 100, 300, 150, 100);
//    CGPathAddCurveToPoint(path, NULL, 100, 150, 100, 0, 150, 100);
//    CGPathAddCurveToPoint(path, NULL, 120, 230, 105, 542, 10, 10);
//    
//    // 設置路徑信息
//    [keyFrameAni setPath:path];
//    // 設置執行時間
//    [keyFrameAni setDuration:5.f];
//    
//    [button.layer addAnimation:keyFrameAni forKey:@"222"];
    
    
    
      // 過渡 變形
//    CATransition *transition = [CATransition animation];
//    
//    // 過渡動畫CATransition 依靠type/subType改變動畫效果
//    transition.duration = 2.f;
//    
//    // 動畫類型
//    //[transition setType:kCATransitionMoveIn];
//    [transition setType:@"cameraIrisHollowClose"];
//    // 動畫方向
//    [transition setSubtype:kCATransitionFromLeft];
//    
//    [button.layer addAnimation:transition forKey:@"333"];
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章