4:抽屉菜单

DIFF

构建弹性动画贝塞尔曲线的控制点(3点贝塞尔曲线)的偏移值

image-20210611102355413.png

MenuView动画

由两部分动画构成

  • 第一部分,是菜单从屏幕外平移到屏幕内,时间大概3s
[UIView animateWithDuration:0.3 animations:^{
            self.frame = self.bounds;
        }];
  • 第二部分,是启动刷帧定时器 CADisplayLink ,通过drawrect 贝塞尔曲线实现动画
CADisplayLink {
   CALayer *sideHelperPresentationLayer   =  (CALayer *)[helperSideView.layer presentationLayer];
    CALayer *centerHelperPresentationLayer =  (CALayer *)[helperCenterView.layer presentationLayer];
    CGRect centerRect = centerHelperPresentationLayer.frame;
    CGRect sideRect = sideHelperPresentationLayer.frame; 
    diff = sideRect.origin.x - centerRect.origin.x;
    
    [self setNeedsDisplay];
}

drawRect {
  UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(0, 0)];
    [path addLineToPoint:CGPointMake(self.frame.size.width - menuBlankWidth, 0)];
    [path addQuadCurveToPoint:CGPointMake(self.frame.size.width - menuBlankWidth, self.frame.size.height) controlPoint:CGPointMake(keyWindow.frame.size.width/2+diff, keyWindow.frame.size.height/2)];
    [path addLineToPoint:CGPointMake(0, self.frame.size.height)];
    [path closePath];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddPath(context, path.CGPath);
    [[UIColor orangeColor] set];
    CGContextStrokePath(context);
}

// 收起动画同理

MenuView上子视图阶梯弹出动画

        UIView *menuButton = self.subviews[i];
        menuButton.transform = CGAffineTransformMakeTranslation(-90, 0);
// i*(0.3/self.subviews.count 这样可以达到从上到下逐个弹出的特效
        [UIView animateWithDuration:0.7 delay:i*(0.3/self.subviews.count) usingSpringWithDamping:0.6f initialSpringVelocity:0.0f options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction animations:^{
            menuButton.transform =  CGAffineTransformIdentity;
        } completion:NULL];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,229评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,208评论 25 708
  • 年轻人也很需要仪式感,如果喜欢,我希望你不要隔着屏幕跟我表白。 1. 橙子以前暗恋一个男生,每天来到教室,第一时间...
    诗水年华阅读 743评论 2 0
  • 你需要多受一点苦,然后才会真正谦恭; 不然,你那自以为是的聪明和藐视一切的优越感迟早要毁了你。
    爱吃柚子的小斯阅读 328评论 0 0
  • ,@,,@,,@,,,,,@,@@,,@,,,,
    real拼阅读 152评论 0 0