GrowingTextView icon indicating copy to clipboard operation
GrowingTextView copied to clipboard

When the number of text lines excels the maxNumberOfLines, the text view will scroll the top then bottom quickly, just like a flash

Open shayanbo opened this issue 11 years ago • 8 comments

When the number of text lines excels the maxNumberOfLines, the text view will scroll the top then bottom quickly, just like a flash

shayanbo avatar Jul 24 '14 08:07 shayanbo

i'm seeing this issue. It's especially prominent when using in tableviewcell. on reload, the textview shows top part for a quick second then jumps to bottom.

rajatk avatar Aug 06 '14 14:08 rajatk

i'm seeing this issue. It's especially prominent when using in tableviewcell. on reload, the textview shows top part for a quick second then jumps to bottom.

rajatk avatar Aug 06 '14 14:08 rajatk

i'm seeing this issue. It's especially prominent when using in tableviewcell. on reload, the textview shows top part for a quick second then jumps to bottom.

rajatk avatar Aug 06 '14 14:08 rajatk

If you want a quick fix, you can turn off animation.

HaloZero avatar Sep 13 '14 01:09 HaloZero

If you want a quick fix, you can turn off animation.

HaloZero avatar Sep 13 '14 01:09 HaloZero

@HaloZero , i turned the animation off like that: messageField.animateHeightChange = NO; //turns off animation but still.... anything else i need to do?

Tx.

Shahar2k5 avatar Oct 29 '14 12:10 Shahar2k5

@HaloZero , i turned the animation off like that: messageField.animateHeightChange = NO; //turns off animation but still.... anything else i need to do?

Tx.

Shahar2k5 avatar Oct 29 '14 12:10 Shahar2k5

I don't believe so, are you still getting the bug?

HaloZero avatar Oct 29 '14 19:10 HaloZero

Yeah, still the same. On the simulator, work OK. On the iPad the bug exist.

Shahar2k5 avatar Oct 29 '14 19:10 Shahar2k5

Yeah, still the same. On the simulator, work OK. On the iPad the bug exist.

Shahar2k5 avatar Oct 29 '14 19:10 Shahar2k5

I found this issue on iPhone6/6+, too. The HPTextViewInternal.contentSize.height behaves strangely.

tsaisean avatar Dec 03 '14 04:12 tsaisean

I found this issue on iPhone6/6+, too. The HPTextViewInternal.contentSize.height behaves strangely.

tsaisean avatar Dec 03 '14 04:12 tsaisean

fix this method with :

   - (CGFloat)measureHeight
   {
      if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)])
      {
        // This is the code for iOS 7. contentSize no longer returns the correct value, so
        // we have to calculate it.
        //
        // This is partly borrowed from HPGrowingTextView, but I've replaced the
        // magic fudge factors with the calculated values (having worked out where
        // they came from)

        CGRect frame = self.internalTextView.bounds;

        // Take account of the padding added around the text.

        UIEdgeInsets textContainerInsets = self.internalTextView.textContainerInset;
        UIEdgeInsets contentInsets = self.internalTextView.contentInset;

        CGFloat leftRightPadding = textContainerInsets.left + textContainerInsets.right + self.internalTextView.textContainer.lineFragmentPadding * 2 + contentInsets.left + contentInsets.right;
        CGFloat topBottomPadding = textContainerInsets.top + textContainerInsets.bottom + contentInsets.top + contentInsets.bottom;

        frame.size.width -= leftRightPadding;
        frame.size.height -= topBottomPadding;

        NSString *textToMeasure = self.internalTextView.text;
        if ([textToMeasure hasSuffix:@"\n"])
        {
            textToMeasure = [NSString stringWithFormat:@"%@-", self.internalTextView.text];
        }

        // NSString class method: boundingRectWithSize:options:attributes:context is
        // available only on ios7.0 sdk.

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];

        NSDictionary *attributes = @{ NSFontAttributeName: self.font, NSParagraphStyleAttributeName : paragraphStyle };

        CGRect size = [textToMeasure boundingRectWithSize:CGSizeMake(CGRectGetWidth(frame), MAXFLOAT)
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                               attributes:attributes
                                                  context:nil];

        CGFloat measuredHeight = ceilf(CGRectGetHeight(size) + topBottomPadding);
        return measuredHeight;
       }
       else
       {
           return self.internalTextView.contentSize.height;
       }
   }

truculent avatar Mar 05 '15 13:03 truculent

fix this method with :

   - (CGFloat)measureHeight
   {
      if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)])
      {
        // This is the code for iOS 7. contentSize no longer returns the correct value, so
        // we have to calculate it.
        //
        // This is partly borrowed from HPGrowingTextView, but I've replaced the
        // magic fudge factors with the calculated values (having worked out where
        // they came from)

        CGRect frame = self.internalTextView.bounds;

        // Take account of the padding added around the text.

        UIEdgeInsets textContainerInsets = self.internalTextView.textContainerInset;
        UIEdgeInsets contentInsets = self.internalTextView.contentInset;

        CGFloat leftRightPadding = textContainerInsets.left + textContainerInsets.right + self.internalTextView.textContainer.lineFragmentPadding * 2 + contentInsets.left + contentInsets.right;
        CGFloat topBottomPadding = textContainerInsets.top + textContainerInsets.bottom + contentInsets.top + contentInsets.bottom;

        frame.size.width -= leftRightPadding;
        frame.size.height -= topBottomPadding;

        NSString *textToMeasure = self.internalTextView.text;
        if ([textToMeasure hasSuffix:@"\n"])
        {
            textToMeasure = [NSString stringWithFormat:@"%@-", self.internalTextView.text];
        }

        // NSString class method: boundingRectWithSize:options:attributes:context is
        // available only on ios7.0 sdk.

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];

        NSDictionary *attributes = @{ NSFontAttributeName: self.font, NSParagraphStyleAttributeName : paragraphStyle };

        CGRect size = [textToMeasure boundingRectWithSize:CGSizeMake(CGRectGetWidth(frame), MAXFLOAT)
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                               attributes:attributes
                                                  context:nil];

        CGFloat measuredHeight = ceilf(CGRectGetHeight(size) + topBottomPadding);
        return measuredHeight;
       }
       else
       {
           return self.internalTextView.contentSize.height;
       }
   }

truculent avatar Mar 05 '15 13:03 truculent

fix this method with :

   - (CGFloat)measureHeight
   {
      if ([self respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)])
      {
        // This is the code for iOS 7. contentSize no longer returns the correct value, so
        // we have to calculate it.
        //
        // This is partly borrowed from HPGrowingTextView, but I've replaced the
        // magic fudge factors with the calculated values (having worked out where
        // they came from)

        CGRect frame = self.internalTextView.bounds;

        // Take account of the padding added around the text.

        UIEdgeInsets textContainerInsets = self.internalTextView.textContainerInset;
        UIEdgeInsets contentInsets = self.internalTextView.contentInset;

        CGFloat leftRightPadding = textContainerInsets.left + textContainerInsets.right + self.internalTextView.textContainer.lineFragmentPadding * 2 + contentInsets.left + contentInsets.right;
        CGFloat topBottomPadding = textContainerInsets.top + textContainerInsets.bottom + contentInsets.top + contentInsets.bottom;

        frame.size.width -= leftRightPadding;
        frame.size.height -= topBottomPadding;

        NSString *textToMeasure = self.internalTextView.text;
        if ([textToMeasure hasSuffix:@"\n"])
        {
            textToMeasure = [NSString stringWithFormat:@"%@-", self.internalTextView.text];
        }

        // NSString class method: boundingRectWithSize:options:attributes:context is
        // available only on ios7.0 sdk.

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];

        NSDictionary *attributes = @{ NSFontAttributeName: self.font, NSParagraphStyleAttributeName : paragraphStyle };

        CGRect size = [textToMeasure boundingRectWithSize:CGSizeMake(CGRectGetWidth(frame), MAXFLOAT)
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                               attributes:attributes
                                                  context:nil];

        CGFloat measuredHeight = ceilf(CGRectGetHeight(size) + topBottomPadding);
        return measuredHeight;
       }
       else
       {
           return self.internalTextView.contentSize.height;
       }
   }

truculent avatar Mar 05 '15 13:03 truculent

thx truculent! Great fix.

ghost avatar Apr 24 '15 08:04 ghost

thx truculent! Great fix.

ghost avatar Apr 24 '15 08:04 ghost

thx truculent! Great fix.

ghost avatar Apr 24 '15 08:04 ghost