1
votes

Finally, I have a reason to ask something, instead of scouring endless hours of the joys of Stack Overflow.

Here's my situation: I have an UIImageView with one UIImage inside it. I'm transforming the entire UIImageView via CGAffineTranforms, to scale it height-wise and keep it at a specific angle. I'm feeding it this transform data through two CGPoints, so it's essentially just calculating the angle and scale between these two points and transforming.

Now, the transforming is working like a charm, but I recently came across the UIImage method resizableImageWithCapInsets, which works just fine if you set the frame of the image manually (ie. scale using a frame), but it seems that using transforms overrides this, which I guess is sort of to be expected since it's Core Graphics doing it's thing.

My question is, how would I go about either a) adding cap insets after transforming the image or b) doing the angle & scaling via a frame?

Note that the two points providing the data are touch points, so they can differ very much, which is why creating a scaled rectangle at a specific angle is tricky at best.

To keep you code hungry geniuses happy, here's a snippet of the current way I'm handling scaling (only doing cap insets when creating the UIImage):

float xDiff = (PointB.x - PointA.x) / 2;
float yDiff = (PointB.y - PointA.y) / 2;

float angle = [self getRotatingAngle:PointA secondPoint:PointB];

CGPoint pDiff = CGPointMake(PointA.x + xDiff, PointA.y + yDiff);

self.center = pDiff;

// Setup a new transform
// Set it up with a scale and an angle
double distance = sqrt(pow((PointB.x - PointA.x), 2.0) + pow((PointB.y - PointA.y), 2.0));
float scale = 1.0 * (distance / self.image.size.height);
CGAffineTransform transformer = self.transform;
transformer = CGAffineTransformConcat(CGAffineTransformMakeScale(1.0, scale), CGAffineTransformMakeRotation(angle));

// Apply the transformer
self.transform = transformer;
1
I may be misunderstanding what you're saying, but it seems you're just trying to maintain the aspect ratio for a given height?Mike M
More or less, yes. I'm only scaling an image on one axis, but I need specific pixels at the top and bottom of that axis to stay at their original size (just like with cap insets), while stretching the middle part of the image.Dids
Maybe you can try using the built-in aspect ratio feature of the UIImageView and the resizableImageWithCapInsets setting of UIImage.Mike M
I've tried, but CGAffineTransform seems to be where the problem's at. It's ignoring resizableImageWithCapInsets completely, which is why I posted here, as I haven't seen an issue like this before.Dids
The proper solution to this can be seen here: stackoverflow.com/questions/17002331/…Dids

1 Answers

0
votes

Adding a proper answer to this. The answer to the problem can be found here.