Fun shadow effects using custom CALayer shadowPaths
来源:互联网 发布:淘宝首页图片不显示 编辑:程序博客网 时间:2024/05/20 23:58
I recently had to improve the performance of a few views that utilized CALayer-based shadows on rounded-rect UIView objects. On this particular iPad application, when the device was rotated, the views rotated quite a lot slower than we would have hoped. It wasn’t a show-stopper, but the jerky rotation animation made it look cheap and unpolished. The easiest way to have our cake, and eat it too, was to set a custom CGPath to the layer’s shadowPath property. This told UIKit to set the inside of the path to opaque, reducing the amount of work the rendering engine needed to perform.
The resulting image, as you can see above, has a shadow as you’d expect. But since we’ve declared the shape the path will have, the iPad can drastically improve its rendering performance.
Through that process however, I decided to see what sort of effects I could pull off by passing in a path otherthan the default rectangular bounds of the layer. Since you can create any sort of path you want, I considered the different effects I could get away with by making non-rectangular paths and using them as shadows.
Trapezoidal CGPath
By carefully drawing a trapezoidal shape below and slightly beneath the view, you can give the illusion of depth.
Elliptical CGPath
Just like the trapezoid, there are other effects you can achieve by playing with simple shapes for the use of creating shadows.
Paper-curl effect
By using a control point on a bezier curve, you can make the bottom side of the shadow curve inward, making it appear like the view is printed on paper that has been curled inward.
More possibilities than can be covered
There are plenty of other possibilities, more than can be covered here. Creating CGPathRef objects, either using UIBezierCurve or by using Quartz2D drawing methods, can easily step through composing shadows. Use a CGAffineTransform object to manipulate your path to stretch, scale, or rotate it as needed. Once you realize what your possibilities are, you can add an extra degree of polish to your application with very little effort.
If you want to play with the source use to create these examples, make sure you download the Xcode project ShadowTest.
Please post comments of any fun variations you manage to come up with!
Note: Special thanks go out to my beautiful wife Deanna for the picture of her Blood Elf Mage cosplay outfitshe put together for Halloween.
From: http://nachbaur.com/blog/fun-shadow-effects-using-custom-calayer-shadowpaths
- Fun shadow effects using custom CALayer shadowPaths
- Fun shadow effects using custom CALayer shadowPaths
- Fun shadow effects using custom CALayer shadowPaths
- Animating Pie Slices Using a Custom CALayer
- CALayer shadow &
- Shader Effects: Shadow Mapping
- CSS3 Shadow Effects
- Shadow effect with custom shapes
- Shadow Mapping Using OpenGL
- Using Custom Draw
- Using custom client attributes
- 【Unity Shaders and Effects Cookbook】Using Textures for Effects
- IOS Performance之CALayer shadow Sucks!
- Animate CALayer custom properties with CoreAnimation
- 了解CSS3的文字阴影效果 - Text Shadow effects
- 【Unity Shaders】Using Textures for Effects介绍
- Shadow removal using bilateral filtering
- Using the Server Custom Actions
- SQL UNION 和 UNION ALL 操作符
- Cocos2d-x制作太空射击游戏
- 移动2D游戏框架 Cocos2d-x 学习笔记
- 【iOS-cocos2d-X 游戏开发之二】【必看篇】总结阐述Cocos2d-X与Cocos2d-iphone区别
- BOOST静态编译
- Fun shadow effects using custom CALayer shadowPaths
- URL 编码:CFURLCreateStringByAddingPercentEscapes
- 【Cocos2d-X(1.x 2.x) 修复篇】iOS6 中 libcurl.a 无法通过armv7s编译以及iOS6中无法正常游戏横屏的解决方法
- [Java教程]将Java Application转换成.exe可执行文件
- android fragment(android.support.v4.app.Fragment和android.app.Fragment区别)
- LayoutInflater的inflate函数
- open和fopen的区别联系
- android xml-----Sax解析
- 第一周 项目一 月份季节的转换