Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS-带阴影的Quartzcore自定义UIView_Ios_Uiview_Nib_Shadow_Quartz Core - Fatal编程技术网

IOS-带阴影的Quartzcore自定义UIView

IOS-带阴影的Quartzcore自定义UIView,ios,uiview,nib,shadow,quartz-core,Ios,Uiview,Nib,Shadow,Quartz Core,我正在实现一个自定义UIView以显示在UIScrollview中。问题是我需要视图投下阴影,所以我做到了: #import <QuartzCore/QuartzCore.h> @implementation CustomView -(void)setupView{ self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOpacity = 0.5; self.layer.sha

我正在实现一个自定义UIView以显示在UIScrollview中。问题是我需要视图投下阴影,所以我做到了:

#import <QuartzCore/QuartzCore.h>
@implementation CustomView

-(void)setupView{


  self.layer.shadowColor = [UIColor blackColor].CGColor;
  self.layer.shadowOpacity = 0.5;
  self.layer.shadowRadius = 1;
  self.layer.shadowOffset = CGSizeMake(.6f, .6f);
  self.layer.cornerRadius = 2;

  [...]

}

-(id)initWithFrame:(CGRect)frame{
  if((self = [super initWithFrame:frame])){
    [self setupView];
  }

  return self;
}

[...]
#导入
@实现自定义视图
-(无效)设置视图{
self.layer.shadowColor=[UIColor blackColor].CGColor;
self.layer.shadowOpacity=0.5;
self.layer.shadowRadius=1;
self.layer.shadowOffset=CGSizeMake(.6f,.6f);
self.layer.cornerRadius=2;
[...]
}
-(id)initWithFrame:(CGRect)帧{
if((self=[super initWithFrame:frame])){
[自我设置视图];
}
回归自我;
}
[...]
关键是,当我构建并运行这个程序时,scrollview速度非常慢,我只需要删除我在“self.layer”中的那些行,scrollview就会再次快速平滑地运行


向我的自定义视图添加阴影的正确方法是什么?

这和移动
ui视图时必须进行的所有重绘有关

如果栅格化图层,它将变得更加平滑,这应该可以做到:

self.layer.rasterizationScale = [UIScreen mainScreen].scale;
self.layer.shouldRasterize = YES;
您可以尝试添加阴影路径:

self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds];

这可能会有更多帮助。

这是一种更平滑但仍然不流畅的方法。在这之后我还能做些什么吗?不是真的,这会栅格化图层(将其图灵化为图像),然后移动图层,在创建图层时不再重画。你在哪种设备上测试你的应用程序?改变了我的答案,加入了阴影路径。好吧,这有点奇怪。。iPhone4在iPhone4上应该足够平滑,你在滚动时还做了其他事情吗?Als确保scrollview中没有不可见的视图。我添加了[UIBezierPath bezierPathWithRect:self.bounds].CGPath及其流体,但我看不到阴影=)