我有一個問題,我需要旋轉UIImageView並調整大小取決於它是Portraite模式還是橫向模式。UIImageView調整方向更改爲橫向模式編程
我已經設法讓圖像視圖正確旋轉,通過做這個相關問題的答案說:Rotate UIImageView Depending on iPhone Orientation。
這是我對輪換代碼(現在我只專注於它旋轉到左橫向):
- (void)rotateImage:(UIImageView *)image duration:(NSTimeInterval)duration
curve:(int)curve degrees:(CGFloat)degrees
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve:curve];
[UIView setAnimationBeginsFromCurrentState:YES];
float angle = DEGREES_TO_RADIANS(degrees);
CGAffineTransform transform = CGAffineTransformRotate(
CGAffineTransformMakeTranslation(
160.0f-self.view.center.x,
240.0f-self.view.center.y
),angle);
image.transform = transform;
[UIView commitAnimations];
}
?怎樣的UIImageView:
UIImage *image = [UIImage imageNamed:@"picture.png"];
self.testImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
self.testImageView.image = image;
self.testImageView.contentMode = UIViewContentModeScaleAspectFit;
self.testImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
現在發生什麼事是圖像被旋轉,但與橫向模式下的肖像模式具有相同的大小,但居中(我理解爲什麼,因爲我做了旋轉作爲鏈接問題的答案)。
所以,我想要的是圖像全屏查看,因爲原始圖像的尺度適合全屏風景。正如我設定的
UIViewContentModeScaleAspectFit
我原來天真的想法,這將神奇地重新調整,以適應適當的景觀規模。顯然不是這樣。任何提示?
對於「原始圖像具有適合全屏風景的比例」的含義,我並不清楚,但如果您希望圖像在填充圖像視圖時保留其縱橫比(以某些裁剪爲代價) ,你可以嘗試'UIViewContentModeScaleAspectFill'。 – warrenm 2012-04-26 18:08:34
是的,我嘗試了AspectFill,但正如你提到的圖像變大,並顯示在屏幕之外。在這種情況下,我希望它能夠正確縮放,但其代價並不能滿足整個屏幕(因爲原始圖像比例可能不適合iphone橫向屏幕),但現在的問題在於,它是小景觀的方式(根本不調整大小)。 – user373455 2012-04-26 18:15:36