欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS CGPath提升阴影性能

程序员文章站 2022-05-18 10:17:52
     发现应用在itouch4上页面左右滑动或push进一个视图控制器时,非常的卡。最后发现时因为给导航控制器的边框添加了阴影的原因。...

     发现应用在itouch4上页面左右滑动或push进一个视图控制器时,非常的卡。最后发现时因为给导航控制器的边框添加了阴影的原因。

                之前的代码:           


                        - (void)addframeleftline {

                            uicolor *color = [uicolor blackcolor];

                            cgsize offset = cgsizemake(0, 3);

                            float radius = 2;

                            float opacity = 1;

                            self.navigationcontroller.view.layer.shadowcolor = color.cgcolor;

                            self.navigationcontroller.view.layer.shadowoffset = offset;

                            self.navigationcontroller.view.layer.shadowradius = radius;

                            self.navigationcontroller.view.layer.shadowopacity = opacity;

                        }

              修改后的代码:


                        - (void)addframeleftline {

                            cgpathref shadow = cgpathcreatewithrect(cgrectinset(self.navigationcontroller.view.bounds, -5, 0), null);

                            [self.navigationcontroller.view.layer setshadowpath:shadow];

                            [self.navigationcontroller.view.layer setshadowcolor:[[uicolor blackcolor] cgcolor]];

                            [self.navigationcontroller.view.layer setshadowopacity:0.3];

                            [self.navigationcontroller.view.layer setshadowradius:2];

                            cfrelease(shadow);

                        }

 

上一篇: docker知识点

下一篇: iOS反射机制