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

最近狼人杀要做缩小效果 缩小的效果就和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。。。。恩 这样就行了







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值