Question

I'm trying to scale a view Horizontally but i'm not getting the results i expected.

view.bounds = CGRectMake(view.bounds.origin.x, view.bounds.origin.y , view.bounds.size.width * scaleX, view.bounds.size.height );
view.center = CGPointMake(view.bounds.origin.x, view.center.y);

As you can see at the code above, i want to scale the view just to the right side. This is why i changed the center of the view.

The problem is that the view stills scaling to both sides! I did the same logic to scale another UIView vertically and got the result i expected.

Was it helpful?

Solution

Just found the problem.

when setting certer, the new point must be relative to frame, not bounds. so, i get the code:

view.center = CGPointMake(-view.frame.origin.x, view.center.y);

Hope it helps somebody..

Thx for help

OTHER TIPS

If the origin of your view's frame is in the top-left (which is the default), increasing the width of your view should scale it to the right only.

This should work:

view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width * scaleX, view.frame.size.height);

You do not need to adjust the origin/center point to scale only to the right.

Try using an affine transform instead:

view.transform = CGAffineTransformMakeScale(scaleX, 1)

And then setting the center.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top