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