ios layer 動畫(x/y/z軸 旋轉(zhuǎn))

x軸旋轉(zhuǎn):

//第一種
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

//第二種
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        view.transform = CGAffineTransformMakeScale(-1.0, 1.0);
    } completion:^(BOOL finished) {
        //還原回來
        //view.transform = CGAffineTransformMakeScale(1.0, 1.0);
    }];

y軸旋轉(zhuǎn):

CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

z軸旋轉(zhuǎn):

CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
theAnimation.duration=8;
theAnimation.removedOnCompletion = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:0];
theAnimation.toValue = [NSNumber numberWithFloat:3.1415926];
 [yourView.layer addAnimation:theAnimation forKey:@"animateTransform"];

以上縮放是以view的中心點為中心縮放的,如果需要自定義縮放點,可以設(shè)置卯點:

//中心點
[yourView.layer setAnchorPoint:CGPointMake(0.5, 0.5)];

//左上角
[yourView.layer setAnchorPoint:CGPointMake(0, 0)];

//右下角
[yourView.layer setAnchorPoint:CGPointMake(1, 1)];

可設(shè)參數(shù)

theAnimation.repeatCount = 0;
theAnimation.autoreverses = NO;

旋轉(zhuǎn)的另一種實現(xiàn):(以下代碼繞z軸旋轉(zhuǎn)180度)

    [self.topViewController.view.layer setAnchorPoint:CGPointMake(0.5, 0.5)];
    [self.topViewController.view.layer setTransform:CATransform3DMakeRotation(0, 0, 0, 1)];
    [UIView animateWithDuration:8 delay:0.0f options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseIn animations:^{
        [self.topViewController.view.layer setTransform:CATransform3DMakeRotation(3.1415926, 0, 0, 1)];
    } completion:^(BOOL finished) {
    }];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容