2013-11-23 140 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