Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITextView,用户滚动UITextView,但它会恢复到原始位置,有什么问题吗?_Iphone_Objective C_Uiscrollview_Uitextview - Fatal编程技术网

Iphone UITextView,用户滚动UITextView,但它会恢复到原始位置,有什么问题吗?

Iphone UITextView,用户滚动UITextView,但它会恢复到原始位置,有什么问题吗?,iphone,objective-c,uiscrollview,uitextview,Iphone,Objective C,Uiscrollview,Uitextview,我目前有一个UITextView,它包含在UIViewController中,使用以下代码: UIViewController *container = [[UIViewController alloc] init]; container.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 1000); //[UIScreen mainScreen].bounds.size.height containe

我目前有一个
UITextView
,它包含在
UIViewController
中,使用以下代码:

UIViewController *container = [[UIViewController alloc] init];
container.view.frame = CGRectMake(0, 0,
[UIScreen mainScreen].bounds.size.width, 1000);
//[UIScreen mainScreen].bounds.size.height

container.view.userInteractionEnabled = YES;
container.view.clipsToBounds = YES;

UIImageView *imgView = [[UIImageView alloc] 
initWithImage:[UIImage imageNamed:@"myImage.png"]];
imgView.frame = container.view.frame;

imgView.userInteractionEnabled = YES;
[container.view addSubview:imgView];
[imgView release];

UITextView *textContained = [[UITextView alloc] 
initWithFrame:CGRectMake(0, 0, container.view.bounds.size.width, 1000)];
//container.view.bounds.size.height

textContained.font = [UIFont fontWithName:@"Calibri" size:14];
textContained.scrollEnabled = YES;
textContained.editable = NO;

textContained.textColor = [UIColor whiteColor];
textContained.backgroundColor = [UIColor clearColor];
textContained.font = [UIFont boldSystemFontOfSize:14];

textContained.userInteractionEnabled = YES;
textContained.alwaysBounceVertical = YES;
textContained.contentSize = CGSizeMake(container.view.frame.size.width,
container.view.frame.size.height);
然后,我用一些文本设置我的
UItextView
text属性,这些文本超出了当前屏幕大小。然后,我使用以下代码将我的
UITextView
添加到我的容器中

 switch (indexPath.row) {
    case 0:
        textContained.text = @"LOTS AND LOTS OF TEXT";

        [container.view addSubview:textContained];
        [self.navigationController pushViewController:container animated:YES];
        [textContained release];

        break; 
    default:
        break;
 }
 [container release];
当我测试这段代码时,文本在
UITextView
中显示得很好,一切看起来都正常。但问题是当我试图向下滚动查看文本的其余部分时。每次我向下滚动时,
UITextView
都会滚动回其原始位置。我已经尝试了几种方法来让它工作,但我想我需要一些新的眼睛来看看我做错了什么


非常感谢您的帮助。

首先,您不想设置UITextView的contentSize,因为它是由文本长度自动确定的

尝试使textView的高度变小。例如:

UITextView *textContained = [[UITextView alloc] 
initWithFrame:CGRectMake(0, 0, container.view.bounds.size.width, 50)];
给它更多的文字,比如:

textContained.text = @"LOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\n\nLOTS AND LOTS OF TEXT\nLOTS AND LOTS OF TEXT\n";

尝试删除textContained.contentSize=。。。看到了吗?我觉得其他的一切都很好。你的建议让我发现我没有减去我的标签栏的大小。非常感谢你。这让我抓狂…需要一些新鲜的眼睛。