I've got a strange problem using UIButtons
, type custom
. I'm placing 4 of those buttons on a UIScrollview
, rotating each button by a random angle using CGAffineTransform
. Now it seems that the buttons themselves change size depending on the angle of rotation.
UIGraphicsBeginImageContext(tempCtxSize);
[cookbookImage drawInRect:CGRectMake(imgOffsetX, imgOffsetY+frmOffsetY, cookbookImage.size.width, cookbookImage.size.height)];
[cookbookFrame drawInRect:CGRectMake(0.0f, frmOffsetY, cookbookFrame.size.width, cookbookFrame.size.height)];
UIImage *combinedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
…
UIButton *cookbookViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cookbookViewButton setFrame:CGRectMake(0.0f, 0.0f, combinedImage.size.width, combinedImage.size.height)];
[cookbookViewButton setBackgroundColor:[UIColor clearColor]];
[cookbookViewButton setBackgroundImage:combinedImage forState:UIControlStateNormal];
CGAffineTransform rotation = [cookbookViewButton transform];
rotation = CGAffineTransformRotate(rotation, angle); // some random angle
[cookbookViewButton setTransform:rotation];
This is a system bug:
" Important
If a view’s transform property does not contain the identity transform, the frame of that view is undefined and so are the results of its autoresizing behaviors."
from: Handling Layout Changes Automatically Using Autoresizing Rules
Solution: set the parent view's autoResizeSubviews to NO.
parentView.autoresizesSubviews = NO;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With