我有一个UITextView(iOS4.2.1 - iPad),我试图将其作为一种“下拉窗口”,供用户根据需要调整大小。我正在使用平移手势识别器来跟踪用户手指,然后根据手指移动的距离调整UITextView框架的大小。一切都很好 - 除了UITextView中的文本在帧扩展超过一定大小后被“切断”。如果我与文本交互(用手指轻弹/滚动),它都会正确重新绘制。我可以在一个非常小的程序中重现这一点 - 见下文。有人见过这个吗?我已经尝试了所有通常的'黑客'(即强行设置滚动位置 - 修改文本等 - 所有'工作'但有缺点)
提前感谢任何指示...
重现它的测试程序如下(只需创建一个基于标准视图的iPad应用程序,然后将以下内容粘贴到主ViewController中。)运行程序然后将手指向下拖动到页面 - 只有前8行左右将显示文字。
@implementation TextViewTestViewController
- (void)createAndLoadTextView
{
theTextView = [[UITextView alloc] initWithFrame:CGRectZero];
theTextView.font = [UIFont systemFontOfSize:27];
theTextView.backgroundColor = [UIColor redColor];
theTextView.opaque = YES;
theTextView.text = @"1 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"2 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"3 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"4 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"5 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"6 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"7 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"8 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"9 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"10 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"11 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"12 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"13 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"14 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"15 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n"
"16 sdnaslkdjfnaskjdnfkjsndfsdfknknskdfnlk\n";
[self.view addSubview:theTextView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createAndLoadTextView];
UIPanGestureRecognizer* panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onPanGesture:)] autorelease];
[self.view addGestureRecognizer:panGesture];
UITapGestureRecognizer* tapGesture = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapGesture:)] autorelease];
[self.view addGestureRecognizer:tapGesture];
}
- (void)onPanGesture:(UIPanGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan ||gesture.state == UIGestureRecognizerStateChanged)
{
CGFloat yDelta = [gesture translationInView:self.view].y;
[gesture setTranslation:CGPointZero inView:self.view];
theTextView.frame = CGRectMake(0, 0, self.view.bounds.size.width, theTextView.bounds.size.height + yDelta);
}
}
- (void)onTapGesture:(UIPanGestureRecognizer*)gesture
{
//'reset'
[theTextView removeFromSuperview];
[theTextView release];
theTextView = nil;
[self createAndLoadTextView];
}
@end
答案 0 :(得分:1)
您可能希望在几何体更改后尝试在文本视图上调用setNeedsDisplay。