2013-11-23 55 views
0

我想修改框架的UIImageView當一個特定的旋轉發生,但當我改變它的UIImage內UIImageView看起來不受影響,如果我NSLog UIImageView幀大小改變了,但它沒有反映在觀點上,爲什麼會發生這種情況?更改框架的UIImageView

@property (strong, nonatomic) IBOutlet UIImageView *couponBg; 

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
    if ((UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) && 
     UIDeviceOrientationLandscapeRight == [[UIDevice currentDevice] orientation])   { 
     self.couponBg.frame = CGRectMake(0, 0, self.couponBg.frame.size.width, self.couponBg.frame.size.height); 
     NSLog(@"FRAME:%@", NSStringFromCGRect(self.couponBg.frame)); 
     self.couponBg.frame = CGRectZero; 
     NSLog(@"FRAME:%@", NSStringFromCGRect(self.couponBg.frame)); 
    } 
} 

我得到正確的幀大小中的NSLog:

2013年11月23日17:05:00.674 - - - - [10302:70B] FRAME:{{0,0} ,{320,199}}

2013年11月23日17:05:00.674 - - - - [10302:70B] FRAME:{{0,0},{0,0}}

但在視圖中圖像總是相同的大小?這是爲什麼發生?

+1

我認爲最有可能的罪魁禍首是,你實際上沒有將已添加到你的視圖中的'UIImageView'分配給'self.couponBg'你能證實你已經完成了嗎? – Adam

回答

0

當我做了旋轉時,問題與CGATransform和Autolayout有關。

0

這是從蘋果的UIView單證採取:

autoresizesSubviews一個布爾值,它確定 接收機是否自動調整它的子視圖當其邊界變化。 @property(nonatomic)BOOL autoresizesSubviews當設置爲YES時, 接收器在其邊界更改時調整子視圖的大小。 默認值爲YES。

您應該確保在UIImageView中設置此值,並且應該將UIImage.autoresizingMask設置爲正確的值。

+0

我加了self.couponBg.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.couponBg.autoresizesSubviews = YES;但我得到了同樣的結果。我不知道你在說什麼UIImage.autoresizingMask導致UIImage沒有這個屬性。 – Godfather

+1

您可以發佈您的代碼來進行輪換嗎? – Greg