更改UIImageView的框架



当发生特定旋转时,我试图修改UIImageView的帧,但当我更改它时,UIImageView内的UIImage看起来不会受到影响,如果我NSLog 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]帧:{{0,0},{320,199}}

2013-11-23 17:05:00.674----[10302:70b]帧:{{0,0},{0、0}}

但是在视图中,图像总是相同的大小?为什么会发生这种情况?

这是从苹果UIView文档:

autoresizesSubviews一个布尔值,用于确定当其边界发生变化时,接收器会自动调整其子视图的大小。@属性(非原子)BOOL autoresizesSubviews当设置为YES时接收器在其边界改变时调整其子视图的大小。这个默认值为YES。

您应该确保在UIImageView中设置了此值,并将UIImage.atoresizingMask设置为正确的值。

当我进行旋转时,问题与CGATransform和Autolayout有关。

最新更新