Mar*_*wie 16 iphone cocoa-touch core-graphics uibutton
我正在努力旋转UIBUtton的imageView属性而不缩放它.有问题的图像是24x18 - 宽度比它高 - 但是一旦旋转到位,图像就会被缩放以保持这些尺寸 - 留下一个非常挤压的图像.我怎么能阻止这个?
以下是我的代码..
-(IBAction)rotateButton
{
NSLog( @"Rotating button" );
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:.5f];
if( CGAffineTransformEqualToTransform( button.imageView.transform, CGAffineTransformIdentity ) )
{
button.imageView.transform = CGAffineTransformMakeRotation(M_PI/2);
} else {
button.imageView.transform = CGAffineTransformIdentity;
}
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
这不,如果我申请将变换按钮,而不是button.imageView发生,所以我猜那就是我没有设置正确的ImageView的属性.
你的线索和嘘声是最受欢迎的
M.
Nik*_*nov 54
在视图中某处的视图初始化时应用以下代码.这会有所帮助.你上面得到的答案不是一个真正的答案:)
button.imageView.clipsToBounds = NO;
button.imageView.contentMode = UIViewContentModeCenter;
Run Code Online (Sandbox Code Playgroud)
我发现 UIButtons 的 UIImageView 属性表现得非常奇怪——它们的一些属性似乎是只读的,包括您在这里讨论的 UIViewContentMode 设置。
我发现的最佳解决方案是使用单独的 UIImageView 来模拟“包含图像的按钮”设置,并在其顶部放置一个空的自定义样式的 UIButton。为您提供更多的灵活性来管理图像。
归档时间: |
|
查看次数: |
8590 次 |
最近记录: |