我使用UIButtons
遇到一个奇怪的问题,输入custom
。我将{4}个按钮放在UIScrollview
上,使用CGAffineTransform
以随机角度旋转每个按钮。现在看来按钮本身会根据旋转角度改变大小。
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];
答案 0 :(得分:2)
这是一个系统错误:
“Important
如果视图的转换属性不包含标识转换,则该视图的框架是未定义的,其自动调整行为的结果也是如此。”
来自:Handling Layout Changes Automatically Using Autoresizing Rules
解决方案:将父视图的autoResizeSubviews设置为NO。
parentView.autoresizesSubviews = NO;
答案 1 :(得分:0)
不要设置cookbookViewButton的框架 - 设置边界。