gpt4 book ai didi

uiscrollview - UITextView、setContentOffset 和缺少底部

转载 作者:行者123 更新时间:2023-12-04 19:08:19 27 4
gpt4 key购买 nike

出于某种奇怪的原因,当设置 scrollofset 时,我的 UITextView 的文本显示为裁剪。

这是它的样子:
enter image description here

执行以下操作后会发生这种情况:

        textview.contentInset = UIEdgeInsetsZero;
[textview setContentOffset:CGPointMake(0, startypos + offset_yshift) animated:NO];

我尝试手动设置 contentSize.height,但这引入了另一种奇怪的行为,内容偏移似乎被忽略了..

''Edit'':这是用于实例化文本字段的代码:
  CGRect myImageRect = CGRectMake(-50.0f, -50.0f, 40.0f, 40.0f);
textview = [[UITextView alloc] initWithFrame: myImageRect];
textview.autocapitalizationType = UITextAutocapitalizationTypeNone;
[textview setScrollEnabled:YES];
textview.hidden = YES;
textview.contentInset = UIEdgeInsetsZero;
textview.opaque = NO;
textview.backgroundColor = [UIColor clearColor];
textview.textColor = [UIColor colorWithWhite:1 alpha:1];
textview.textAlignment = NSTextAlignmentCenter;
textview.frame = CGRectMake(0, 0, 250, 30);
textview.scrollEnabled = NO;

以及检查每一帧内容定位的“更新”代码:
  // setting the actual size here
UITextPosition * pos = [textview positionFromPosition: textview.endOfDocument offset:nil];
CGRect therect = [textview caretRectForPosition:pos];

CGRect frame = textview.frame;

if([textview.text length] == 0){
frame.size.height = 30;
} else {
frame.size.height = therect.origin.y + therect.size.height;
}

// and here, we're changing the frame variable's height to max to 50
if(frame.size.height > 50){
frame.size.height = 50;
}
frame.size.width = desiredwidth; // some other variable

textview.frame = frame;

/*

... snip, unrelated code ...

*/

// later on

textview.contentInset = UIEdgeInsetsZero;
[textview setContentOffset:CGPointMake(0, startypos + offset_yshift) animated:NO];

可以想象, setContentOffset 位是导致问题的原因。

到底是怎么回事?

最佳答案

请从上一篇文章中尝试这个

CGPoint offset = CGPointMake(0, self.textView.contentSize.height - self.textView.frame.size.height);
[self.textView setContentOffset: CGPointMake(0,0) animated:NO];
or
[self.textView setContentOffset:bottomOffset animated:YES];

【发帖】: UITextView contentOffset on iOS 7 “上一篇”\

关于uiscrollview - UITextView、setContentOffset 和缺少底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19005434/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com