iOS開發只簡單動畫實現

1.動畫旋轉:動畫

    [UIViewbeginAnimations:@"View Flip"context:nil];     //聲明,@"XX"爲標題,
    [UIViewsetAnimationDuration:1.25];                           //持續時間
    [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut];  //設置動畫曲線
          //加入新的座標
     
          //旋轉視圖
    [UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromRight
                          forView:self.viewcache:YES];  ///調用

 

2.左右晃動動畫:spa

 // start the wiggling animation
   CGFloatrotation =0.03;
   
   CABasicAnimation*shake = [CABasicAnimation animationWithKeyPath:@"transform"];
    shake.duration = 0.13;
    shake.autoreverses = YES;
    shake.repeatCount  = MAXFLOAT;
    shake.removedOnCompletion = NO;
    shake.fromValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform,-rotation, 0.0 ,0.0 ,1.0)];
    shake.toValue  = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform, rotation, 0.0 ,0.0 ,1.0)];
   
    [self.layeraddAnimation:shake forKey:@"shakeAnimation"];
  
//而後在退出的時候移除
 [self.layer removeAnimationForKey:@"shakeAnimation"];

 

三、code

    CATransform3D transformBefore = CATransform3DIdentity;
    transformBefore.m34 = 0.0005;
    transformBefore = CATransform3DRotate(transformBefore,(M_PI/180*270), 0, 1, 0);
    instroduceLayer.layer.transform = transformBefore;   
    instroduceLayer.layer.anchorPoint = CGPointMake(0.0, 0.5);
   
    [UIViewanimateWithDuration:1animations:^{
        CATransform3D transform = CATransform3DIdentity;//單位矩陣
        transform.m34 = 0.0005;
        transform = CATransform3DRotate(transform,(M_PI/180*0), 0, 1, 0);
        instroduceLayer.layer.transform = transform;
    }];
相關文章
相關標籤/搜索