小编Mic*_*ael的帖子

CGAffineTransform:UIButton上的旋转调整按钮图像的大小

我有一个奇怪的问题UIButtons,请输入custom.我将4个按钮放在a上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];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch rotation cgaffinetransform

5
推荐指数
1
解决办法
1525
查看次数

标签 统计

cgaffinetransform ×1

cocoa-touch ×1

iphone ×1

rotation ×1