美文网首页
两种页面消失的动画效果

两种页面消失的动画效果

作者: 马戏团小丑 | 来源:发表于2017-06-17 10:49 被阅读59次

核心代码:

// 宏
#define TimerPerTime 0.01
#define TotalTime 0.75

// 属性初始化
 self.radius = WINDOW_height * 0.5;
 self.perH = TimerPerTime / TotalTime * self.radius;

// 按钮点击事件
self.timer = [NSTimer scheduledTimerWithTimeInterval:TimerPerTime target:self selector:@selector(updateAnim) userInfo:nil repeats:YES];

// 定时器事件
- (void)updateAnim{
self.radius = self.radius - self.perH;
[self round:self.radius];
}
- (void)round:(CGFloat)radius{
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y)
                                 radius:radius
                                 startAngle:0
                                 endAngle:2 * M_PI
                                 clockwise:NO];    
    CAShapeLayer *shaperLayer = [CAShapeLayer layer];
    shaperLayer.path = circlePath.CGPath;
    self.layer.mask = shaperLayer;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(TotalTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.timer invalidate];
        self.timer = nil;
        [self removeFromSuperview];
    });
}

核心代码:

// 属性初始化
self.radius = 0;
self.perH = TimerPerTime / TotalTime * WINDOW_height;

// 按钮点击事件
self.timer = [NSTimer scheduledTimerWithTimeInterval:TimerPerTime target:self selector:@selector(updateAnim) userInfo:nil repeats:YES];

// 定时器事件
- (void)updateAnim{
self.radius = self.radius + self.perH;
[self round:self.radius];
}
- (void)round:(CGFloat)radius{
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.center.x, self.center.y)
                                                              radius: radius
                                                          startAngle:0
                                                            endAngle:2 * M_PI
                                                           clockwise:NO];
    [path appendPath:circlePath];
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = path.CGPath;
    self.layer.mask = shapeLayer;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(TotalTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.timer invalidate];
        self.timer = nil;
        [self removeFromSuperview];
    });
}

相关文章

网友评论

      本文标题:两种页面消失的动画效果

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