9

I have the below menu style layout that mimics facebook. I would like to have a dropshadow on the left side like below however the code I am using with layer shadows makes the application LAGGY. I have not been able to find a good alternative solution. Does anyone have an alternative for creating a dropshadow that does not affect application performance?

[self.navController.view.layer setShadowOffset:CGSizeMake(0, 1)];
[self.navController.view.layer setShadowColor:[[UIColor darkGrayColor] CGColor]];
[self.navController.view.layer setShadowRadius:8.0];
[self.navController.view.layer setShadowOpacity:0.8];

The above code is the code I am currently using that causes application performance issues.

The below image is what I would like to achieve but without having to use the above code.

enter image description here

Bot
  • 11,868
  • 11
  • 75
  • 131

3 Answers3

11

It should help to specify a shadow path, e.g.,

CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:self.navController.view.layer.bounds].CGPath;
[self.navController.view.layer setShadowPath:shadowPath]

According to the CALayer documentation, "Specifying an explicit path usually improves rendering performance."

Bot
  • 11,868
  • 11
  • 75
  • 131
norelius
  • 126
  • 1
  • 2
  • Awesome! this helped alot however I do notice a little bit of performance still but not to bad. – Bot Feb 17 '12 at 22:46
4

You can just inset the views bounds and set the shadow path:

UIEdgeInsets contentInsets = UIEdgeInsetsMake(10, 0, 0, 0);
CGRect shadowPathExcludingTop = UIEdgeInsetsInsetRect(self.bounds, contentInsets);
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathExcludingTop].CGPath;
Adam Waite
  • 19,175
  • 22
  • 126
  • 148
0

I for myself would just add a UIView containing that shadow as a subview and reposition it as soon as the view on the right side is animated. (e.g. draw that shadow with layers or core graphics)

fscheidl
  • 2,281
  • 3
  • 19
  • 33