如何对图层阴影不透明度进行动画处理?
我有一个视图,我已将其图层不透明度设置为 1。
theView.layer.shadowOpacity = 1.0;
当视图位于屏幕下方时,这看起来很好。当我将此视图向上移动以与另一个有阴影的视图齐平时,它们看起来不太好。有没有办法可以将图层上的 shadowOpacity
设置为 0?我尝试使用动画块,但似乎该属性不可设置动画。
编辑: 请求代码不起作用:
[UIView animateWithDuration:1.0 animations:^{
splitView2.layer.shadowOpacity = 0;}
completion:NULL];
I have a view on which I've set the layerOpacity to 1.
theView.layer.shadowOpacity = 1.0;
This looks fine when the view is farther down the screen. When I move this view up to be flush with another view that has a shadow, they don't look good. Is there a way I can animate the shadowOpacity
on my layer to be 0? I tried using an animation block but it seems as if this property is not animatable.
EDIT: Request for code that doesn't work:
[UIView animateWithDuration:1.0 animations:^{
splitView2.layer.shadowOpacity = 0;}
completion:NULL];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将正常工作:
对于 Swift 3.0:
This will work properly:
For Swift 3.0:
我已将上面的代码放在 UIView 的一个小扩展中:
用法如下:
它尚未经过彻底测试。但为我工作。
(还发布在此处)
I've put above code in a little extension of UIView:
Usage like:
It's not thoroughly tested. but worked for me.
(Also posted here)
下面的代码对我有用
1)添加 QuartzCore 框架工作
2)导入QuartzCore框架,
在需要的地方添加以下代码
就可以了。根据您的要求更改代码格式
The below code work for me
1)Add QuartzCore frame work
2)Import QuartzCore frame work
Add the following Code in the required place
It will works. Change the format of the code as per your requirement
这是一个材料设计,就像上面的一些动画一样
它也可以通过 Carthage 作为框架在此处使用 https://github.com/sevenapps/SVNMaterialButton
Here's a material design like take on some of the above with animations
It's also available here as framework through Carthage https://github.com/sevenapps/SVNMaterialButton