2010-06-03 55 views
1

在最初的UIImageView我把它設置爲如何更新UIImageView的contentMode?

mCurrentImageView.contentMode = UIViewContentModeLeft; 

因此,如果設備旋轉我會改變contentMode ,但它沒有任何效果。我該如何解決它?

if ([UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeLeft || [UIDevice currentDevice].orientation == UIInterfaceOrientationLandscapeRight) { 
     mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit; 
    } 

回答

3

[UIDevice orientation]不返回這些標識符的方向。從文檔,該消息將返回以下:

typedef enum { 
    UIDeviceOrientationUnknown, 
    UIDeviceOrientationPortrait, 
    UIDeviceOrientationPortraitUpsideDown, 
    UIDeviceOrientationLandscapeLeft, 
    UIDeviceOrientationLandscapeRight, 
    UIDeviceOrientationFaceUp, 
    UIDeviceOrientationFaceDown 
} UIDeviceOrientation; 

要改變內容模式,你應該做的視圖控制器代碼東西willRotate消息:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     mCurrentImageView.contentMode = UIViewContentModeScaleAspectFit; 
    } 
} 
+0

謝謝rickharrison – RAGOpoR 2010-06-03 16:01:50

+0

沒問題。如果它適合你,請隨時提供我的答案。 – rickharrison 2010-06-03 17:41:53

相關問題