我有一个 textView 作为 a 的子视图UIView
,它是根据此方案的 scrollView 的子视图:
-UIScrollView *scrollView
-UIView *containerView
-UITextView *textView
-MKMapView *mapView
-UIImageView *imageView
我在旋转过程中遇到问题,在从纵向到横向的过渡中,TextView 被缩短,并且不再显示旋转前可见的文本的一部分。相反,从风景到肖像的作品。Cosa 可以吗?textView 完全在代码中创建,没有 IBOutlet。
UITextView
是可变高度,里面的contentSize设置viewDidLoad
如下:
- (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 一起工作。