0

I have a scrollView which has an origin.y = -200, size.height = 200 and contentSize.height = 270.

On the main view I have a tableView with the touch of a button. the scrollView animates from the top to origin.y = 64. Because the scrollView and tableView share the same color background, I want a shadow outside the the scrollView to make the views separate.

But when I set the scrollView.layer.masksToBounds = YES it automatically expands to its full contentSize which is 270. If I comment out the maskToBounds I get no shadow. What am I missing? Thank you in advance

_addScroller.layer.shadowColor = [UIColor blackColor].CGColor;
_addScroller.layer.shadowOffset = CGSizeMake(0, 2);
_addScroller.layer.shadowOpacity = .7f;
_addScroller.layer.shadowRadius = 2;
//    _addScroller.layer.masksToBounds = NO;
CGPathRef path = [UIBezierPath bezierPathWithRect:_addScroller.frame].CGPath;
_addScroller.layer.shadowPath = path;

This is with masksToBounds = NO; it automatically sets the frame.height to the contentSize.height enter image description here

Community
  • 1
  • 1
snksnk
  • 1,566
  • 4
  • 21
  • 46

1 Answers1

0

What if you add the scrollview inside another view (of the same size as the scrollview, i.e. 200px height) and set the container view's shadow and maskToBounds?

I think a similar situation is in this question.

Community
  • 1
  • 1
insys
  • 1,288
  • 13
  • 26
  • I have already seen that post and I have considered that option. But why it automatically adjusts to the contentSize? – snksnk Feb 12 '14 at 11:13
  • Not sure but adding scrollView inside a container view seems to be a rather common way of doing things, at least according to e.g. [this](http://stackoverflow.com/questions/12091998/how-to-mask-a-uiscrollview) and [this](http://stackoverflow.com/questions/5709543/mask-overlay-on-uiscrollview). – insys Feb 12 '14 at 11:52