English 中文(简体)
IOS - 在图像上添加阴影边框使其变重和无反应
原标题:IOS - Adding shadowed border to image makes it heavy and unresponsive

I am developing an iPad application. In my application users can move, rotate and scale images. I ve noticed that when I add a 3d shadowed border to the images, it makes them incredibly heavy and unresponsive. I add the border using this code:

self.layer.MasksToBounds = false;
self.layer.ShadowColor = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
self.layer.ShadowOpacity = 1.0f;
self.layer.ShadowOffset = CGSizeMake(0, 2.5f);

为什么发生这种事?我有什么办法解决这个问题?

最佳回答

这是CaLayer 阴影的一个众所周知的问题。 设置 < code> shadowPath 属性, 您将会看到良好的性能提升 。

阴影路径只能是您图像视图的边框路径。 您应该能够设置它一次, 层变换会随着图像的缩放等不断更新 。

问题回答

您也应设置

self.layer.ShouldRasterize = YES

这会将层分解。 如果设置为 NO( 默认), 所有在图层上应用的过滤器和阴影都会被重新计算好几次, 这需要相当大的性能。 特别是在滚动视图或表格视图中 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签