kam*_*iro 5 uiscrollview uitextview ios7
出于某些奇怪的原因,当设置了scrollofset时,我的UITextView文本会出现裁剪.
这是它的样子:

这样做发生在:
textview.contentInset = UIEdgeInsetsZero;
[textview setContentOffset:CGPointMake(0, startypos + offset_yshift) animated:NO];
Run Code Online (Sandbox Code Playgroud)
我尝试手动设置contentSize.height,但这引入了另一个奇怪的行为,其中内容偏移似乎被忽略..
''编辑'':这是用于实例化文本字段的代码:
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;
Run Code Online (Sandbox Code Playgroud)
以及检查每帧内容定位的"更新"代码:
// 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];
Run Code Online (Sandbox Code Playgroud)
可以想象,setContentOffset位是导致问题的原因.
到底是怎么回事?
我在 iOS7 中使用 UITextField 遇到了一个非常相似的问题 - 看起来几乎完全相同。我的也与内容插图有关。
解决方案(对我来说) - 是从 nib/storyboard 中消除 UITextField 并实例化它并将其纯粹从代码添加到视图中。之后的行为如预期的那样起作用。
我不知道发生了什么,除了可能是 iOS7 / XCode 5 的错误......很想知道这是否也能解决你的问题。
| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |