我有一個TextView作爲UIView
的子視圖,這是本方案的一個滾動視圖的子視圖:UITextView的變化高度從縱向去到風景
-UIScrollView *scrollView
-UIView *containerView
-UITextView *textView
-MKMapView *mapView
-UIImageView *imageView
我有旋轉過程中出現問題,在從縱向到橫向的過渡將縮短TextView,並且不再顯示在旋轉之前可見的文本的一部分。相反,從風景到肖像作品。科莎可以嗎? textView完全用代碼創建,沒有IBOutlet。
的UITextView
是可變的高度,以viewDidLoad
的contentSize被設置如下:
- (void)viewDidLoad
{
[super viewDidLoad];
//....
self.textView = [[UITextView alloc]init];
self.textView.backgroundColor =[UIColor clearColor];
CGRect frame;
frame = self.textView.frame;
frame.size.height= [self.textView contentSize].height;
[self.textView setContentSize:self.textView.contentSize];
self.textView.frame = frame;
NSLog(@"The contentSize of TextView is %@",NSStringFromCGSize
(self.textView.contentSize));
//The contentSize of TextView is {0, 161032}
//........
}
的willRotateToInterfaceOrientation:duration
看起來像:
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
CGSize containerSize = CGSizeMake(768, 5000);
self.scrollView.contentSize = containerSize;
self.containerView.frame = CGRectMake(0, 0, 768, 5000);
[self layoutPortrait];
}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
CGSize containerSize = CGSizeMake(1004, 5000);
self.scrollView.contentSize = containerSize;
self.containerView.frame = CGRectMake(0, 0, 1024, 5000);
[self layoutLandscape];
}
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){
CGSize containerSize = CGSizeMake(1004, 5000);
self.scrollView.contentSize = containerSize;
self.containerView.frame = CGRectMake(0, 0, 1024, 5000);
[self layoutLandscape];
}
}
這處理幀的旋轉的兩種方法是:
-(void) layoutPortrait{
//...
NSLog(@"the height of textView è %f", self.textView.contentSize.height);
//the height of textView è 161032.000000
self.textView.frame =CGRectMake(56, 490, self.viewImages.frame.size.width, self.textView.contentSize.height);
//.....
}
-(void) layoutLandscape{
//......
NSLog(@"The height of textView è %f", self.textView.contentSize.height);
/*The height of textView è 2872.000000
(This after rotation from portrait to landscape)*/
self.textView.frame = CGRectMake(170, 495, self.viewImages.frame.size.width, self.textView.contentSize.height);
//......
}
我想說的是旋轉過程中textView的高度保持不變。隨着UIImageView和MKMapView的工作。
默認'autoresizingMask'值是'UIViewAutoresizingNone'。如果mask沒有設置爲textView,並且superView設置了「clipsToBounds」,你可能需要檢查textView的superview'autoresizingMask'。 –