애니메이션 CABasicAnimation

4494 단어
수정 날짜: 2016-12-20 수정 횟수: 0
 // 
    CABasicAnimation *basic=[CABasicAnimation animation];
    //  
    basic.keyPath=@"bounds";
   // basic.keyPath=@"transform.rotation";
       // 
    basic.fromValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
    // 
    basic.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)];
    // 
    basic.duration=10;
    // 
    basic.repeatCount=1;
    // 
    basic.beginTime=CACurrentMediaTime()+2;
    // 
    basic.removedOnCompletion=NO;
    basic.fillMode=kCAFillModeBackwards;
   // 
    [self.ballImageView .layer addAnimation:basic forKey:nil];

빙글빙글 돌다

// 
    CABasicAnimation *basic=[CABasicAnimation animation];
    //  
    //basic.keyPath=@"bounds";
   basic.keyPath=@"transform.rotation";
       // 
    //basic.fromValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 50, 50)];
    // 
    //basic.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 300, 300)];
    basic.toValue=@(M_PI *2);
    // 
    basic.duration=1;
    // 
    basic.repeatCount=5;
    // 
   // basic.beginTime=CACurrentMediaTime()+2;
    // 
    basic.removedOnCompletion=NO;
    basic.fillMode=kCAFillModeBackwards;
   // 
    [self.ballImageView .layer addAnimation:basic forKey:nil];

프레임 애니메이션

// 
    CAKeyframeAnimation *keyframeAnimation=[CAKeyframeAnimation animation];
    // 
    keyframeAnimation.keyPath=@"position";
    // 
    NSValue *poiont1=[NSValue valueWithCGPoint:CGPointMake(100, 50)];
    NSValue *poiont2=[NSValue valueWithCGPoint:CGPointMake(100, 650)];
    NSValue *poiont3=[NSValue valueWithCGPoint:CGPointMake(100, 350)];
    NSValue *poiont4=[NSValue valueWithCGPoint:CGPointMake(100, 650)];
     NSValue *poiont5=[NSValue valueWithCGPoint:CGPointMake(100, 500)];
     NSValue *poiont6=[NSValue valueWithCGPoint:CGPointMake(100, 650)];
     NSValue *poiont7=[NSValue valueWithCGPoint:CGPointMake(100,600)];
     NSValue *poiont8=[NSValue valueWithCGPoint:CGPointMake(100, 650)];
    
    // 
    keyframeAnimation.values=@[poiont1,poiont2,poiont3,poiont4,poiont5,poiont6,poiont7,poiont8];
    // 
    keyframeAnimation.keyTimes=@[@(0),@(0.3),@(0.4),@(0.5),@(0.6),@(0.7),@(0.8),@(0.9)];
    // 
    keyframeAnimation.duration=3.0;
    
    [self.ballImageView.layer addAnimation:keyframeAnimation forKey:nil];

베셀 곡선

// 
    CAKeyframeAnimation * keyframeA=[CAKeyframeAnimation animation];
    // 
    keyframeA.keyPath=@"position";
    // 
    // 
    //UIBezierPath *bezierPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 100, 150, 250)];
    UIBezierPath *bezierPath=[UIBezierPath bezierPathWithArcCenter:self.view.center radius:150 startAngle:0 endAngle:M_PI *2 clockwise:YES];
    // 
    keyframeA.path=bezierPath.CGPath;
    // 
    [bezierPath closePath];
    // 
    keyframeA.duration=1.0;
     // 
    keyframeA.removedOnCompletion=NO;
    
    keyframeA.fillMode=kCAFillModeForwards;
    
    keyframeA.repeatCount=100;
    
    [self.ballImageView.layer addAnimation:keyframeA forKey:nil];

그룹 애니메이션

  // 
    CAAnimationGroup *group=[CAAnimationGroup animation];
    // 
    CABasicAnimation *animation1=[CABasicAnimation animation];
    // 
    animation1.keyPath=@"transform.rotation";
    // 
    animation1.toValue=@(M_PI *2);
    
    
    // 
    CABasicAnimation *animation2=[CABasicAnimation animation];
    animation2.keyPath=@"bounds";
    animation2.toValue=[NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];
    
    // 
    CABasicAnimation *animation3=[CABasicAnimation animation];
    animation3.keyPath=@"transform.translation.x";
    animation3.toValue=@(500);
    
    // 
    group.animations=@[animation1,animation2,animation3];
    // 
    group.duration=2.0;
    // 
    group.delegate=self;
    // 
    group.removedOnCompletion=NO;
    group.fillMode=kCAFillModeForwards;
    
    // 
    [self.ballImageView.layer addAnimation:group forKey:nil];

animationWithKeyPath 값:


transform.scale = 비례 변환
transform.scale.x =  
transform.scale.y =  
transform.rotation.z =  
opacity =  
margin
zPosition
backgroundColor     
cornerRadius     
borderWidth
bounds
contents
contentsRect
cornerRadius
frame
hidden
mask
masksToBounds
opacity
position
shadowColor
shadowOffset
shadowOpacity
shadowRadius

좋은 웹페이지 즐겨찾기