美文网首页
动态遮罩实现

动态遮罩实现

作者: iOS小乔 | 来源:发表于2017-07-21 17:55 被阅读61次
    dynamicMask.gif
    -(void)initSubViews{
    
    CGFloat maskW = 150;
    
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.maskView.bounds];
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:maskW startAngle:0.0 endAngle:2*M_PI clockwise:NO];
    [path appendPath:circlePath];
    
    _shaperLayer = [CAShapeLayer layer];
    _shaperLayer.path = path.CGPath;
    self.maskView.layer.mask = _shaperLayer;
    }
    
    - (IBAction)progressSlider:(UISlider *)sender {
    
    CGFloat maskW = sender.value*self.view.bounds.size.height;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.maskView.bounds];
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.center.x, self.view.center.y) radius:maskW startAngle:0.0 endAngle:2*M_PI clockwise:NO];
    [path appendPath:circlePath];
    _shaperLayer.path = path.CGPath;
    self.maskView.layer.mask = _shaperLayer;
    
    }
    
    - (IBAction)begainAction {
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [NSValue valueWithCGPoint:self.img_book.center];
    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(70, 90)];
    animation.duration = 2.0;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.img_book.layer addAnimation:animation forKey:@"positionAnimation"];
    
    CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.values = @[@1,@1.2,@1];
    scaleAnimation.duration = 2.0;
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.removedOnCompletion = NO;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.img_book.layer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
    
    
    }
    

    相关文章

      网友评论

          本文标题:动态遮罩实现

          本文链接:https://www.haomeiwen.com/subject/uuiekxtx.html