objective-c – 为CALayer阴影路径设置动画
发布时间:2020-12-16 06:02:50 所属栏目:百科 来源:网络整理
导读:我正在为CALayer制作阴影路径. 框架正确调整大小,但阴影不会缩放. 相反,阴影从最终大小CGSize(20,20)开始,并在整个动画中保持,即使我将shadowPath设置为初始值 [CATransaction begin];[CATransaction setAnimationDuration: 0];[CATransaction setDisableAct
我正在为CALayer制作阴影路径.
框架正确调整大小,但阴影不会缩放. 相反,阴影从最终大小CGSize(20,20)开始,并在整个动画中保持,即使我将shadowPath设置为初始值 [CATransaction begin]; [CATransaction setAnimationDuration: 0]; [CATransaction setDisableActions: TRUE]; layer.frame = CGRectMake(0,10,10); layer.shadowPath = [UIBezierPath bezierPathWithRect:layer.bounds].CGPath; [CATransaction commit]; [CATransaction begin]; [CATransaction setValue:[NSNumber numberWithFloat:10] forKey:kCATransactionAnimationDuration]; layer.frame = CGRectMake(0,20,20); layer.shadowPath = [UIBezierPath bezierPathWithRect:tile.bounds].CGPath; [CATransaction commit]; 解决方法
起初,小阴影与阴影.
按下按钮时,方形和阴影一起变大. 主要代码如下: [CATransaction begin]; [CATransaction setAnimationDuration:5.0]; CAMediaTimingFunction *timing = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; [CATransaction setAnimationTimingFunction:timing]; layer.frame = CGRectMake(0,100,100); [CATransaction commit]; CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; shadowAnimation.duration = 5.0; shadowAnimation.fromValue = (id)[UIBezierPath bezierPathWithRect:CGRectMake(0,50,50)].CGPath; shadowAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:CGRectMake(0,100)].CGPath; [layer addAnimation:shadowAnimation forKey:@"shadow"]; 您可以从GitHub下载此项目并运行它. https://github.com/weed/p120812_CALayerShadowTest 这个问题对我来说很难! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Flexigrid系列使用教程(四)同时操作选择的多条数据
- applicationContext.xml和dispatcher-servlet.xml的区别
- [Unity基础]xml在unity中的使用
- c# – 在Entity Framework中使用简单查询,性能非常差
- c# – 使用ASP.NET验证器比较复选框和文本框是否有一种优雅
- 03.29.2005 林大单一打球日记——心情不好,状态不佳
- reactjs – 在React中,setState和forceUpdate之间有什么区别
- C#文件上传的简单实现
- Qt之正则表达式 - QRegExp
- actionscript-3 – 如何防止某些外语字体的文字移位?