国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

CAKeyframeAnimation

2019-11-09 18:12:14
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

CAKeyframeAnimation跟CABasicAnimation的區(qū)別是:CABasicAnimation只能從一個(gè)Value變到另一個(gè)Value,而CAKeyframeAnimation會(huì)將這些數(shù)值保存在數(shù)組中或者以路徑(path)形式保存.

另附代碼如下:

- (instancetype)initWithFrame:(CGRect)frame withSuperView:(UIView *)superView{    if (self = [super initWithFrame:frame]) {                self.superView = superView;        self.borderColor = [UIColor whiteColor];        self.fillColor = [UIColor colorWithRed:(arc4random_uniform(255))/255.0 green:(arc4random_uniform(255))/255.0 blue:(arc4random_uniform(255))/255.0 alpha:1];        self.backgroundColor = [UIColor clearColor];        self.layer.anchorPoint = CGPointMake(0.5, 1);    }    return self;}- (void)addAnimationView{    // 初始化    self.transform = CGAffineTransformMakeScale(0, 0);    self.alpha = 0;        [UIView animateWithDuration:0.5 delay:0.0 usingSPRingWithDamping:0.6 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaSEOut animations:^{        self.transform = CGAffineTransformIdentity;        self.alpha = 0.9;    } completion:^(BOOL finished) {            }];    // 隨機(jī)數(shù)    NSInteger i = arc4random_uniform(2);    NSInteger rotationDirection = 1 - (2*i);        // 繪制路徑    UIBezierPath *heartTravelPath = [UIBezierPath bezierPath];    [heartTravelPath moveToPoint:self.center];        CGPoint endPoint = CGPointMake(self.centerX + (rotationDirection) * arc4random_uniform(2*self.width), self.superView.height/6.0 + arc4random_uniform(self.superView.height/4.0));    CGFloat x = (self.width/2.0 + arc4random_uniform(2*self.width)) * rotationDirection;    CGFloat y = MAX(endPoint.y ,MAX(arc4random_uniform(8*self.width), self.width));    CGPoint controlPoint1 = CGPointMake(self.centerX + x, self.superView.height - y);    CGPoint controlPoint2 = CGPointMake(self.centerX - 2*x, y);        [heartTravelPath addCurveToPoint:endPoint controlPoint1:controlPoint1 controlPoint2:controlPoint2];        CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];    keyFrameAnimation.path = heartTravelPath.CGPath;    keyFrameAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];    keyFrameAnimation.duration = liveAnimationDuration + endPoint.y/self.superView.height;    [self.layer addAnimation:keyFrameAnimation forKey:@"positionOnPath"];        [UIView animateWithDuration:liveAnimationDuration animations:^{        self.alpha = 0.0;    } completion:^(BOOL finished) {        [self removeFromSuperview];    }];}- (void)drawRect:(CGRect)rect{        [self.fillColor setFill];    [self.borderColor setStroke];        CGFloat drawingPadding = 2.0;    CGFloat curveRadius = floor((CGRectGetWidth(rect) - 2*drawingPadding) / 4.0);        UIBezierPath *heartPath = [UIBezierPath bezierPath];        CGPoint tipLocation = CGPointMake(floor(CGRectGetWidth(rect) / 2.0), CGRectGetHeight(rect) - drawingPadding);    [heartPath moveToPoint:tipLocation];        CGPoint topLeftCurveStart = CGPointMake(drawingPadding, floor(CGRectGetHeight(rect) / 3));        [heartPath addQuadCurveToPoint:topLeftCurveStart controlPoint:CGPointMake(topLeftCurveStart.x, topLeftCurveStart.y + curveRadius)];        [heartPath addArcWithCenter:CGPointMake(topLeftCurveStart.x + curveRadius, topLeftCurveStart.y) radius:curveRadius startAngle:M_PI endAngle:0 clockwise:YES];        CGPoint topRightCurveStart = CGPointMake(topLeftCurveStart.x + 2*curveRadius, topLeftCurveStart.y);    [heartPath addArcWithCenter:CGPointMake(topRightCurveStart.x + curveRadius, topRightCurveStart.y) radius:curveRadius startAngle:M_PI endAngle:0 clockwise:YES];        CGPoint topRightCurveEnd = CGPointMake(topLeftCurveStart.x + 4*curveRadius, topRightCurveStart.y);    [heartPath addQuadCurveToPoint:tipLocation controlPoint:CGPointMake(topRightCurveEnd.x, topRightCurveEnd.y + curveRadius)];        [heartPath fill];        heartPath.lineWidth = 1;    heartPath.lineCapStyle = kCGLineCapRound;    heartPath.lineJoinStyle = kCGLineCapRound;    [heartPath stroke];}

注:

values:動(dòng)畫(huà)移動(dòng)的點(diǎn)

path:動(dòng)畫(huà)移動(dòng)路徑。path只對(duì)CALayer的anchorPoint和position起作用。path比values優(yōu)先級(jí)高,所以如果path有值,那么values將被忽略.

keyTimes:為對(duì)應(yīng)的關(guān)鍵幀設(shè)置對(duì)應(yīng)的時(shí)間點(diǎn)(取值范圍為0到1.0),keyTimes中的每一個(gè)時(shí)間值都對(duì)應(yīng)values中的每一幀.默認(rèn)各個(gè)關(guān)鍵幀的時(shí)間是平分的.


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 手机| 屏东市| 张家港市| 河津市| 邵东县| 镇江市| 漠河县| 朝阳县| 蓝田县| 乾安县| 平远县| 尖扎县| 鄂托克前旗| 博爱县| 长治县| 尤溪县| 永修县| 临沂市| 武城县| 龙口市| 乌兰察布市| 房产| 丹凤县| 新安县| SHOW| 红安县| 临夏市| 东台市| 英吉沙县| 泸州市| 金湖县| 邹平县| 富平县| 永川市| 张掖市| 和田市| 龙岩市| 晋州市| 安溪县| 华阴市| 广东省|