1
votes

I'm building an ios application. In my application I have a view which contains amongst other things an ImageView I've created a border around the image view by adding subviews around it. Each subview has got it's own unique values (5,10,15,10)

I give my users the ability to move, rotate and scale the super view. Currently every scale causes my border views to change as well. I want the borders around the interior image to remain in the same original, unscaled size.

As you can see in the screenshot, I have two UIViews. They both have the same shadow border (see code) The first one is scaled X 2. The result is not only a scaled view, but also a scaled shadow. My question is, how can I scale only the view, and not its shadow.

    view.layer.MasksToBounds = false;
    view.layer.ShadowColor = [[UIColor alloc] initWithRed:0 green:0 blue:0 alpha:0.5].CGColor;
    view.layer.ShadowOpacity = 0.5f;
    view.layer.shadowRadius = 1.0f;
    view.layer.ShadowOffset = CGSizeMake(0, 2.5f);
    UIBezierPath * depthShadowPath = [UIBezierPath bezierPath ];
    [depthShadowPath moveToPoint:CGPointMake( -border , -border ) ];
    [depthShadowPath addLineToPoint:CGPointMake( view.frame.size.width + border , -border ) ];
    [depthShadowPath addLineToPoint:CGPointMake( view.frame.size.width + border , view.frame.size.height + border) ];
    [depthShadowPath addLineToPoint:CGPointMake( -border , view.frame.size.height + border ) ];
    [depthShadowPath addLineToPoint:CGPointMake( -border , -border) ];
    [view.layer setShadowPath:[depthShadowPath CGPath ] ];

enter image description here

How can this be done?

1
Can you add a screenshot for us? I'm picturing 2 different things in my head based on what you said, and can't figure out which one is actually how your project is set up :)WendiKidd
I would have thought it would depend upon how you're changing your border views sizes. Are you using autoResizing masks? Are you manually setting the values? As WendiKidd suggested, we probably have to see a little more, perhaps the code, too (or at least a description of how your code is moving, rotating, scaling the super view, as there are different ways to do it, and thus the solution varies).Rob
did you find a way of doing this?Andres

1 Answers

0
votes

It seems to me that the view might not be redrawn, but just scaled in memory. Try setting view.contentMode = UIViewContentModeRedraw, or manually force a redraw by sending the [view setNeedsDisplay] message.