2013-11-23 3 views
0

특정 회전이 발생하면 UIImageView의 프레임을 수정하려고하는데, 변경하면 UIImageView의 UIImage가 영향을받지 않습니다. 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

나는 가장 가능성이 큰 범인은 실제로 당신이'self.couponBg'에보기에 추가 된'UIImageView'를 할당하지 않았다는 것입니다. 당신이 이것을했는지 확인할 수 있습니까? – 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