Scotty
Scotty

Reputation: 2069

UITextView not 'repainting' after being resized

I have a UITextView (iOS4.2.1 - iPad) which I'm trying to make into a kind of 'pull down window' for users to resize as they see fit. I'm using a pan gesture recogniser to track the users finger and I then resize the UITextView frame according to how far the finger has moved. All fine - except that the text in the UITextView gets 'chopped' once the frame is extended beyond a certain size. If I interact with the text (flick/scroll it with my finger) it all repaints correctly. I can reproduce this in a very small program - see below. Anyone else seen this? I have tried all the usual 'hacks' (i.e. forcibly setting the scroll position - modifying the text etc. - all 'work' but have drawbacks)

Thanks in advance for any pointers...

The test program to reproduce it is as follows (just create a standard view based iPad app then paste the following into the main ViewController.) Run the program then drag your finger down the page - only the first 8 or so lines of text will be displayed.

@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

Upvotes: 1

Views: 422

Answers (1)

hotpaw2
hotpaw2

Reputation: 70703

You might want to try calling setNeedsDisplay on the text view after your geometry change.

Upvotes: 1

Related Questions