English 中文(简体)
UIImageView 旋转并调整大小。
原标题:UIImageView rotate and resize

I want to rotate my UIImageView and set the size according to the aspect ratio. But I have some problems with that. First I paste here my code, then I explain the problem.

imageView.size = CGSizeMake(myWidth, myHeight);
[imageView setContentMode:UIViewContentModeCenter];

So these two lines set the size and the contentMode of my imageView. When I do this the image appears correctly. So when the device is rotated I catch the rotation notification and

if ([self isLandscape]) {
    CGFloat aspect = myHeight / myWidth;
    imageView.size = CGSizeMake(myWidth/aspect, myWidth);
    [self rotateView:imageView withDegree:degree];
    imageView.origin = CGPointMake(x, y);
} else {
    [self rotateView:imageView withDegree:degree];
    imageView.origin = CGPointMake(x, y);
    imageView.size = CGSizeMake(myWidth, myHeight);
}

So then the rotation is done. But you can see that I am also do a resizing.
The problem is that my imageView has a minimum size which cannot be overridden. But I figured out that if I change the contentMode property of my imageView from UIViewContentModeCenter to UIViewContentModeScaleAspectFit then it will work good but the size is smaller than what I expect. Why is that? :( How can I solve this? Please if you have any help!

最佳回答

ScaleAspectFit只会将内容缩放到全部可见且不裁剪的大小。如果您想让内容填充视图并可能裁剪一些部分,您需要使用UIViewContentModeScaleAspectFill

然而,如果您只想强制每个维度的最小尺寸,您可以使用MAX宏。

CGSize mySize = CGSizeMake(myWidth, myHeight);
mySize.x = MAX(mySize.x, myXMin);
mySize.y = MAX(mySize.y, myYMin);
imageView.size = mySize;

另外,只是确认你真的想要横向大小为 (宽*宽/高,宽) 而不仅仅是 (高,宽)

问题回答

暂无回答




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签