iOS Bezier curve

https://www.jianshu.com/p/2316f0d9db65

 

1. Bezier curve

Software: PaintCode: direct drawing, an image producing software Bezier curve

Related concepts: UIBezierPath and CGPath

Method 1: - (void) moveToPoint: (CGPoint) point; // set the starting point of a Bezier curve; corresponds CGPath Method: CG_EXTERN void CGPathMoveToPoint (CGMutablePathRef __nullable path, const CGAffineTransform * __nullable m, CGFloat x, CGFloat y)

Method 2: - (void) addLineToPoint: (CGPoint) point; // linear Bezier curve end point; corresponds CGPath Method: CG_EXTERN void CGPathAddLineToPoint (CGMutablePathRef __nullable path, const CGAffineTransform * __nullable m, CGFloat x, CGFloat y)

Function: B (t) = (1-t) * P0 + t * P1; (0 ≤ t ≤1)

Method 3: - (void) addQuadCurveToPoint: (CGPoint) endPoint controlPoint: (CGPoint) controlPoint; // two yuan Bezier curve, and moveToPoint: (CGPoint) point; used together, point (P0 point) as the start point, endPoint (P2 point) the midpoint, controlPoint (P1 point) as a control point; corresponds CGPath method: CG_EXTERN void CGPathAddQuadCurveToPoint (CGMutablePathRef __nullable path, const CGAffineTransform * __ nullable m, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y)

Function: B (t) = (1-t) * (1-t) * P0 + 2t * (1-t) * P1 + t * t * P2; (0 ≤ t ≤1)

 

Method 4: - (void) addCurveToPoint: (CGPoint) endPoint controlPoint1: (CGPoint) controlPoint1 controlPoint2: (CGPoint) controlPoint2; // three yuan Bezier curve, and the moveToPoint: (CGPoint) point; used together, point (P0 point) as a starting point, endPoint (P3 point) to the end point, controlPoint1 (P1 point) and controlPoint2 (P2 point) as a control point; corresponds CGPath method: CG_EXTERN void CGPathAddCurveToPoint (CGMutablePathRef __nullable path, const CGAffineTransform * __nullable m, CGFloat cp1x, CGFloat cp1y , CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y)

函数:B(t) = (1-t)*(1-t)*(1-t)*P0 + 3t*(1-t)(1-t)P1 + 3t*t*(1-t)P2 +t*t*t*P3;( 0 ≤ t ≤1 )

 

Method 5: - (void) addArcWithCenter: (CGPoint) center radius: (CGFloat) radius startAngle: (CGFloat) startAngle endAngle: (CGFloat) endAngle clockwise: (BOOL) clockwise; // draw a circle with a point arc, center: center radius: radius startAngle: starting angle clockwise: end angle clockwise: whether clockwise;

2. Bezier curve animation +

Steps: 1. Create a Bezier curve

2. Create CAShapeLayer create a layer, the layer is disposed in the path attribute a Bezier curve path, and set some properties of the layer

3. Create animation CABasicAnimation, and added to the layer CAShapeLayer created

Wherein: CABasicAnimation * checkAnimation = [CABasicAnimation animationWithKeyPath: @ "strokeEnd"]; keyPath: determining a start and end point of the animation by strokeStart and strokeEnd; CABasicAnimation in, fromValue and toValue area range determined start and end points are animations

3. Layer mask property application

Page interaction: - (void) animateTransition: (id) transitionContext; executed in the proxy method:

1.获取fromVC:ViewController * fromVC = (ViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKe

2.获取toVC:SecondViewController *toVC = (SecondViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

3.添加到containerView:UIView *contView = [transitionContext containerView];

[contView addSubview:toVC.view];

4. Set the mask is toVC CAShapeLayer, and add attributes for the animation path and CAShapeLayer;

5. At the end of the animation, the mask value is removed: - (void) animationDidStop: (CAAnimation *) anim finished: (BOOL) flag {[self.transitionContext viewControllerForKey: UITransitionContextToViewControllerKey] .view.layer.mask = nil;}

 
 
2 thumbs up
 
Journal
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/itlover2013/p/11426364.html