OGeek|极客世界-中国程序员成长平台

标题: ios - 当按下返回键时,UITableView 中的 UITextView 不会向上滚动 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:18
标题: ios - 当按下返回键时,UITableView 中的 UITextView 不会向上滚动

我想创建一个具有类似 iOS 7 的 Notes 应用程序功能的应用程序。基本上顶部有一行有日期和时间。

我的解决方案是将 UITextView 放在 UITableView 中。第一行是带有日期和时间的 UILabel,第二行是 UITextView。

我根据 UITextView ContentSize 改变了 UITextView 和 UITableViewCell 的高度。

问题是 UITextView 的尺寸很大,所以当用户按回车键时它不会自动滚动。

有没有办法让它正常滚动?



Best Answer-推荐答案


UITextViewUIScrollView 的子类。我将建议一种实现类似功能的替代方法。添加标签 View 作为 TextView 的 subview ,并设置标签高度的contentInset顶部值。

UILabel* label = [UILabel new];
label.text = @"Test";
[label sizeToFit];

CGRect frame = label.frame;
frame.origin.y -= frame.size.height;
[label setFrame:frame];

[self.textView addSubview:label];

[self.textView setContentInset:UIEdgeInsetsMake(label.frame.size.height, 0, 0, 0)];

示例项目: http://sdrv.ms/16JUlVD

关于ios - 当按下返回键时,UITableView 中的 UITextView 不会向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19182404/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4