中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

iOS常用的幾個(gè)動(dòng)畫代碼

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
使用前

        需引入QuartzCore.framework, 并在相關(guān)文件中加入 #import "QuartzCore/QuartzCore.h"

定義

         shakeFeedbackOverlay為UIImageView

設(shè)置

         self.shakeFeedbackOverlay.alpha = 0.0;

         self.shakeFeedbackOverlay.layer.cornerRadius = 10.0; //設(shè)置圓角半徑

1、圖像左右抖動(dòng)

    CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    shake.fromValue = [NSNumber numberWithFloat:-M_PI/32];

    shake.toValue = [NSNumber numberWithFloat:+M_PI/32];

    shake.duration = 0.1;

    shake.autoreverses = YES; //是否重復(fù)

    shake.repeatCount = 4;

    [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];

    self.shakeFeedbackOverlay.alpha = 1.0;

    [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; //透明度變0則消失 } completion:nil];

2、圖像順時(shí)針旋轉(zhuǎn)

    CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

    shake.fromValue = [NSNumber numberWithFloat:0];

    shake.toValue = [NSNumber numberWithFloat:2*M_PI];

    shake.duration = 0.8; shake.autoreverses = NO;

    shake.repeatCount = 1;

    [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];

    self.shakeFeedbackOverlay.alpha = 1.0;

    [UIView animateWithDuration:10.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; } completion:nil];

3、圖像關(guān)鍵幀動(dòng)畫 

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];

    CGMutablePathRef aPath = CGPathCreateMutable();

    CGPathMoveToPoint(aPath, nil, 20, 20);

    CGPathAddCurveToPoint(aPath, nil, 160, 30, 220, 220, 240, 420);

    animation.path = aPath;

    animation.autoreverses = YES;

    animation.duration = 2;

    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

    animation.rotationMode = @"auto";

    [ballView.layer addAnimation:animation forKey:@"position"];

4、組合動(dòng)畫 CAAnimationGroup

    CABasicAnimation *flip = [CABasicAnimation animationWithKeyPath:@"transform.rotation.y"];

    flip.toValue = [NSNumbernumberWithDouble:-M_PI];

    CABasicAnimation *scale= [CABasicAnimation animationWithKeyPath:@"transform.scale"];

    scale.toValue = [NSNumbernumberWithDouble:12];

    scale.duration = 1.5;

    scale.autoreverses = YES;

    CAAnimationGroup *group = [CAAnimationGroup animation];

    group.animations = [NSArray arrayWithObjects:flip, scale, nil];

    group.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    group.duration = 3;

    group.fillMode = kCAFillModeForwards;

    group.removedOnCompletion = NO;

    [ballView.layer addAnimation:group forKey:@"position"];

5、指定時(shí)間內(nèi)旋轉(zhuǎn)圖片

//啟動(dòng)定時(shí)器旋轉(zhuǎn)光圈

- (void)startRotate

{

    self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02

                                                  target:self

                                                selector:@selector(rotateGraduation)

                                                userInfo:nil

                                                 repeats:YES];

}

//關(guān)閉定時(shí)器

- (void)stopTimer

{

    if ([self.rotateTimerisValid])

{

        [self.rotateTimerinvalidate];

        self.rotateTimer = nil;

    }

}

//旋轉(zhuǎn)動(dòng)畫

- (void)rotateGraduation

{

    self.timeCount--;

    if (self.timeCount == 0)

    {

        [self stopTimer];

        // doSomeThing //旋轉(zhuǎn)完畢 可以干點(diǎn)別的

        self.timeCount = 25;

    }

    else

    {

        //計(jì)算角度 旋轉(zhuǎn)

        static CGFloat radian = 150 * (M_2_PI / 360);

        CGAffineTransform transformTmp = self.lightImageView.transform;

        transformTmp = CGAffineTransformRotate(transformTmp, radian);

        self.lightImageView.transform = transformTmp;

    };

}

調(diào)用方法

self.timeCount = 25; //動(dòng)畫執(zhí)行25次

[self startRotate];

標(biāo)簽: seo

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:iOS應(yīng)用發(fā)送SMS短消息代碼

下一篇:Android放大和縮小圖片的代碼