iOS开发 - 柱状图动态展现动画

先来看看效果,正反变化都有:
这里写图片描述

这里博主用了组动画的方式,通过两种转换来完成:
1.通过bounds和position
2.通过transform.scale.y和position

通过bounds和position

1.创建一个layer

  CALayer *itemLayer = [CALayer layer];
    itemLayer.frame = CGRectMake(50, 100, 50, 200);
    itemLayer.backgroundColor = [UIColor redColor].CGColor;
    [baseView.layer addSublayer:itemLayer];

2.写bounds的动画

  CGRect frame = itemLayer.frame;
    CABasicAnimation *aniBounds = [CABasicAnimation animationWithKeyPath:@"bounds"];
    aniBounds.fromValue = [NSValue valueWithCGRect:CGRectMake(50, 100, 50, 0)];
    aniBounds.toValue = [NSValue valueWithCGRect:CGRectMake(50, 100, CGRectGetWidth(frame), CGRectGetHeight(frame))];

3.写position的动画(position在UIView中类似center)

   CABasicAnimation *aniPosition = [CABasicAnimation animationWithKeyPath:@"position"];
    aniPosition.fromValue = [NSValue valueWithCGPoint:CGPointMake(50 + (CGRectGetMaxX(frame)-50)/2, 100)];
    aniPosition.toValue = [NSValue valueWithCGPoint:CGPointMake(50 + (CGRectGetMaxX(frame)-50)/2,100 + (CGRectGetMaxY(frame)-100)/2)];
//需要反方向延伸的
 aniPosition.fromValue = [NSValue valueWithCGPoint:CGPointMake(220 + (CGRectGetMaxX(frame)-220)/2,CGRectGetMaxY(frame))];
    aniPosition.toValue = [NSValue valueWithCGPoint:CGPointMake(220 + (CGRectGetMaxX(frame)-220)/2, 100 + (CGRectGetMaxY(frame) - 100)/2)];

CGRectGetMaxX

CGRectGetMaxX //解释一下,它的意思是获取到 x坐标+width 的值,Y对应 y坐标+height 的值   max代表最大,min代表最小最小时x,y坐标不变,宽度为原来的宽度,高度为0;

4.将两个动画组合起来

  CAAnimationGroup *anis = [CAAnimationGroup animation];
    anis.animations = @[aniBounds,aniPosition];
    anis.duration = 1;
    anis.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
    anis.removedOnCompletion = NO;
    anis.fillMode=kCAFillModeForwards;
    [itemLayer addAnimation:anis forKey:nil];

你也可以尝试不组合,不组合矩形的position是固定的,两端同时延伸,不是我们要的效果,所以用positon来固定位置。

通过transform.scale.y和position

这里和上面的写法是一样的,区别是没有用bounds,改用了transform.scale.y(高的缩放值)

 CABasicAnimation *aniBounds = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"];
    aniBounds.duration = 1;
    aniBounds.fromValue = @0.0;
    aniBounds.toValue = @1.0;
    aniBounds.repeatCount = 1;
    [itemLayer addAnimation:aniBounds forKey:@""];

其他的东西是一样的,也许还有其他的写法,博主暂时想不到了,Demo下载地址:点击下载

如果有其他好的方法欢迎和博主沟通!

回答: 不完全正确。@CrossOrigin注解可以解决本地跨域问题,但在某些情况下可能会遇到一些限制。引用中的报错信息指出,当设置allowCredentials为true时,allowedOrigins不能包含特殊值"*",因为在"Access-Control-Allow-Origin"响应头中不能设置"*"。解决方案是明确列出允许使用credentials的origins,或者考虑使用"allowedOriginPatterns"代替。此外,引用提到除了细粒度、基于注释的配置之外,可能还需要定义一些全局CORS配置。这些配置可以在Spring MVC中声明,并结合细粒度的@CrossOrigin配置。默认情况下,所有origins和GET、HEAD和POST方法都是被允许的。因此,@CrossOrigin可以解决本地跨域问题,但在一些特殊情况下可能需要额外的配置。举个例子,可以在控制器类上使用@CrossOrigin注解来允许跨域访问,并在请求方法上使用@RequestMapping注解来定义具体的请求路径和方法类型。例如: ```java @CrossOrigin @RestController public class PersonController { @RequestMapping(method = RequestMethod.GET) public String add() { // 执行相关操作 } } ```<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [解决springboot添加@CrossOrigin支持跨域不起作用](https://blog.csdn.net/qq_45721173/article/details/124634565)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [注解@CrossOrigin解决跨域问题](https://blog.csdn.net/qq_39176597/article/details/112982244)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodingFire

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值