1
我有一個UITextView(iOS4.2.1 - iPad),我正在嘗試將其製作成一種「下拉窗口」,供用戶在他們認爲合適時調整大小。我使用平移手勢識別器跟蹤用戶手指,然後根據手指移動的距離調整UITextView框架的大小。一切都很好 - 除了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
不那麼簡單,我害怕 - 那是我嘗試的第一件事之一:-( – Scotty 2011-02-09 08:38:49