Vì một số lý do lạ, văn bản của UITextView của tôi xuất hiện bị cắt khi tập hợp scrollofset được đặt.UITextView, setContentOffset và thiếu phần dưới
Đây là những gì nó trông giống như:
Điều này xảy ra sau khi thực hiện:
textview.contentInset = UIEdgeInsetsZero;
[textview setContentOffset:CGPointMake(0, startypos + offset_yshift) animated:NO];
tôi đã cố gắng tự thiết lập contentSize.height, nhưng đó giới thiệu một hành vi kỳ lạ, nơi mà nội dung bù đắp có vẻ là bị bỏ qua ..
'' Chỉnh sửa '': Đây là mã được sử dụng để khởi tạo trường văn bản:
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;
Và "cập nhật" mã để kiểm tra vị trí nội dung mỗi khung:
// 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];
Như bạn có thể tưởng tượng, setContentOffset cắn có là những gì gây ra vấn đề.
Điều gì đang xảy ra?
Bạn đã thử 'hack' được mô tả ở đây chưa? http://stackoverflow.com/a/19137163/1153630 –