禁用UITextView滚动包含视图? [英] Disable UITextView scrolling the containing view?

查看:141
本文介绍了禁用UITextView滚动包含视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIScrollView中有一个UITextView(具体来说,文本视图位于表中的UITableViewCell中)。当我输入文本视图并点击返回以创建一些新行(并且文本视图中的文本变得太长而无法垂直包含)时,它会滚动文本视图本身(这是可以的)和包含它的表/表格单元格(我想阻止它)。有没有办法防止这种行为?

I've got a UITextView inside a UIScrollView (specifically, the text view is in a UITableViewCell in a table). When I type in the text view and hit return to make some new lines (and the text in the text view becomes too long for it to contain vertically), it scrolls both the text view itself (which is okay) and the table/table cell that contains it (which I would like to prevent). Is there some way to prevent this behaviour?


  • UITableView将scrollEnabled设置为NO,但UITextView仍然使其滚动。

  • 我考虑过继承UITextView并重写scrollRectToVisible什么也不做,但我不介意文本视图本身滚动,我想停止它滚动包含视图。

  • 同样,在文本视图中将scrollEnabled设置为NO只会阻止它滚动,而不能阻止它滚动表格。

  • 文本视图不会被键盘遮挡,但它似乎仍然希望靠近屏幕顶部。

  • The UITableView has scrollEnabled set to NO, yet the UITextView still causes it to scroll.
  • I've thought about subclassing UITextView and overriding scrollRectToVisible to do nothing, but I don't mind the text view itself scrolling, I want to stop it scrolling the containing view.
  • Similarly, setting scrollEnabled to NO on the text view only prevents it from scrolling, not the table/table cell.
  • The text view is not obscured by the keyboard, but it seems like it still wants to move closer to the top of the screen.

推荐答案

为了它的价值,我终于通过在编辑时从UITableViewCell中删除UITextView并将其添加到包含表视图的视图控制器来解决这个问题,然后在完成时将其返回到UITableViewCell。

For what it's worth, I've finally resolved this issue by removing the UITextView from the UITableViewCell (and adding it to the view controller that contains the table view) while editing, then returning it to the UITableViewCell when finished.

这篇关于禁用UITextView滚动包含视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆