iOS 水中气泡上浮效果 (后续会加入到水波纹中)

    xiaoxiao2021-03-25  87

        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(200, 200, 25, 25)];

        [view setBackgroundColor:[UIColor redColor]];

        [view.layer setMasksToBounds:YES];

        [view.layer setCornerRadius:25/2];

        [self.view addSubview: view];

        

        UIBezierPath *zigzagPath = [[UIBezierPath alloc] init];

        CGFloat oX = view.frame.origin.x;

        CGFloat oY = view.frame.origin.y;

        CGFloat eX = oX;

        CGFloat eY = oY - 200;

        CGFloat t = 40;

        CGPoint cp1 = CGPointMake(oX - t, ((oY + eY) / 2));

        CGPoint cp2 = CGPointMake(oX + t, cp1.y);

        // the moveToPoint method sets the starting point of the line

        [zigzagPath moveToPoint:CGPointMake(oX, oY)];

        // add the end point and the control points

        [zigzagPath addCurveToPoint:CGPointMake(eX, eY) controlPoint1:cp1 controlPoint2:cp2];

        

        CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

        pathAnimation.duration = 2;

        pathAnimation.path = zigzagPath.CGPath;

        // remains visible in it's final state when animation is finished

        // in conjunction with removedOnCompletion

        pathAnimation.fillMode = kCAFillModeForwards;

        pathAnimation.removedOnCompletion = NO;

        [view.layer addAnimation:pathAnimation forKey:@"movingAnimation"];

    转载请注明原文地址: https://ju.6miu.com/read-13542.html

    最新回复(0)