iOS 每日一记之———————————————仿QQ语音通话隐藏显示效果

来源:互联网 发布:苹果mac双系统切换 编辑:程序博客网 时间:2024/05/17 09:30

最近狼人杀要做缩小效果 缩小的效果就和QQ语音聊天点击收起的动态特效是一样的 。。。。。

恩 闲话少说 直接上代码 。。。

#pragma mark  -- CA缩小动画效果
- (void)animateDismissTransition:(UIView *)view rect:(CGRect)endRect{
    // 1.获取动画缩放结束时的圆形
    UIBezierPath *endPath = [UIBezierPath bezierPathWithOvalInRect:endRect];
    // 2.获取动画缩放开始时的圆形
    CGSize startSize = CGSizeMake(view.frame.size.width * 0.5, view.frame.size.height - ((SCREEN_WIDTH/7.0)/2));
    CGFloat radius = sqrt(startSize.width * startSize.width + startSize.height * startSize.height);
    CGRect startRect = CGRectInset(endRect, -radius, -radius);
    UIBezierPath *startPath = [UIBezierPath bezierPathWithOvalInRect:startRect];
    
    // 3.创建shapeLayer作为视图的遮罩
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = endPath.CGPath;
    view.layer.mask = shapeLayer;
    self.shapeLayer = shapeLayer;
    
    // 添加动画
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
    pathAnimation.fromValue = (id)startPath.CGPath;
    pathAnimation.toValue = (id)endPath.CGPath;
    pathAnimation.duration = 0.8;
    pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    pathAnimation.delegate = self;
    pathAnimation.removedOnCompletion = NO;
    pathAnimation.fillMode = kCAFillModeForwards;
    [shapeLayer addAnimation:pathAnimation forKey:@"packupAnimation"];
}

view是在做动画的那个View   endRect 是你结束之后的坐标位置

我的View 其实就是我最外层的window

接下来是window的拖拽事件

//window的拖拽手势
- (void)panClick:(UIPanGestureRecognizer*)pan{
    if (!_small) {
        return;
    }
    UIApplication *myApplication = [UIApplication sharedApplication];
    UIWindow *myKeyWindow = myApplication.keyWindow;
    for (UIWindow *showWindow in myApplication.windows) {
        if (![showWindow isKindOfClass:NSClassFromString(@"UITextEffectsWindow")]) {
            myKeyWindow = showWindow;
            CGPoint point = [pan locationInView:myKeyWindow];
            CGFloat distance = WCX_SCALE_SCREEN_Height(27);  // 离四周的最小边距
            if (pan.state == UIGestureRecognizerStateEnded) {
                if (point.y <= distance) {
                    point.y = distance;
                    } else if(point.y >= [UIScreen mainScreen].bounds.size.height - distance){
                    point.y = [UIScreen mainScreen].bounds.size.height - distance;
                }else if (point.x <= [UIScreen mainScreen].bounds.size.width/2.0) {
                    point.x = distance;
                    } else{
                    point.x = [UIScreen mainScreen].bounds.size.width - distance;
                }
                [UIView animateWithDuration:0.5 animations:^{
                    pan.view.center = point;
                }];
            } else{
                pan.view.center = point;
                }
            windowEndRect = pan.view.frame;
            smallViewEndRect = windowEndRect;
        }
    }
}

最后是单击window的放大事件。。。。

#pragma mark  -- CA放大动画
- (void)CATapClick{
    AppDelegate *deleage = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [UIView animateWithDuration:1.0 animations:^{
      
    } completion:^(BOOL finished) {
        //deleage.gameWindow.bounds = [UIScreen mainScreen].bounds;
        //deleage.gameWindow.frame = deleage.gameWindow.bounds;
        //deleage.gameWindow.layer.cornerRadius =0;
        //deleage.gameWindow.layer.masksToBounds = YES;
        // 1.获取动画缩放开始时的圆形
        CGRect rect;
        if (windowEndRect.size.height == 0){
            rect = smallViewEndRect;
        } else{
            rect = windowEndRect;
        }
        UIBezierPath *startPath = [UIBezierPath bezierPathWithOvalInRect:rect];
        // 2.获取动画缩放结束时的圆形
        CGSize endSize = CGSizeMake(deleage.gameWindow.frame.size.width * 0.5, deleage.gameWindow.frame.size.height);
        CGFloat radius = sqrt(endSize.width * endSize.width + endSize.height * endSize.height);
        CGRect endRect = CGRectInset(rect, -radius, -radius);
        UIBezierPath *endPath = [UIBezierPath bezierPathWithOvalInRect:endRect];
        // 3.创建shapeLayer作为视图的遮罩
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = endPath.CGPath;
        deleage.gameWindow.layer.mask = shapeLayer;
        self.shapeLayer = shapeLayer;
        // 添加动画
        CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
        pathAnimation.fromValue = (id)startPath.CGPath;
        pathAnimation.toValue = (id)endPath.CGPath;
        pathAnimation.duration = 0.8;
        pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        pathAnimation.delegate = self;
        pathAnimation.removedOnCompletion = NO;
        pathAnimation.fillMode = kCAFillModeForwards;
        [shapeLayer addAnimation:pathAnimation forKey:@"showAnimation"];
    }];
}

appdelegate 不需多言了吧 gameWindow就是狼人杀所在的window。。。。恩 这样就行了







0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 恶魔之眼掉色后怎么办 练瑜伽出汗瑜伽垫手滑怎么办 cf多出来的神器怎么办 脖子痛得低不了怎么办 六岁的孩孑不吃.饭怎么办 大腿肌肉练废了怎么办 吃鸡里的信誉分太低怎么办she 血压高老是晕怎么办27 我腰疼的厉害怎么办 奥克斯空调外机上霜风扇不转怎么办 燃脂膏辣辣的怎么办 减肥期间暴食了怎么办 健身减脂后腹部皮松怎么办 吃减肥药上火怎么办呢 魔域怀旧版新区进不去怎么办 dnf十周年礼盒打开了怎么办 房地产项目完成后企业员工怎么办啊 韩服lol延迟太高怎么办 LOL等级奖励卡掉怎么办 魔域手机号换了怎么办 买的qq号找回了怎么办 买dnf账号被找回怎么办 微博账号已锁定怎么办 抖音账号封手机怎么办 手机号码绑定被别人占用了怎么办 DNF账号给找回了怎么办 转转上被骗了200怎么办 7彩账号被锁定怎么办 猪不吃食没精神怎么办 cf手游签到没给怎么办 cf说停止运行了怎么办 cf端游永久禁赛怎么办 cf端游爆破怕死怎么办 王者荣耀累计扣分12分怎么办 去医院看病没带身份证怎么办 ps4星战2鬼服怎么办 冒险岛英雄五转怎么办 6儿童视力低常怎么办 腰干活累的酸痛怎么办 狗狗体力很差怎么办啊 脉差总是五十多怎么办