GrowingTextView
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
When the number of text lines excels the maxNumberOfLines, the text view will scroll the top then bottom quickly, just like a flash
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.
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.
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.
If you want a quick fix, you can turn off animation.
If you want a quick fix, you can turn off animation.
@HaloZero , i turned the animation off like that: messageField.animateHeightChange = NO; //turns off animation but still.... anything else i need to do?
Tx.
@HaloZero , i turned the animation off like that: messageField.animateHeightChange = NO; //turns off animation but still.... anything else i need to do?
Tx.
I don't believe so, are you still getting the bug?
Yeah, still the same. On the simulator, work OK. On the iPad the bug exist.
Yeah, still the same. On the simulator, work OK. On the iPad the bug exist.
I found this issue on iPhone6/6+, too. The HPTextViewInternal.contentSize.height behaves strangely.
I found this issue on iPhone6/6+, too. The HPTextViewInternal.contentSize.height behaves strangely.
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;
}
}
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;
}
}
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;
}
}
thx truculent! Great fix.
thx truculent! Great fix.
thx truculent! Great fix.