UITextView - 禁用垂直滚动 [英] UITextView - disable vertical scrolling

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

问题描述

如何在UITextView中禁用垂直滚动?我希望它基本上只是水平滚动。

How can I disable vertical scrolling in my UITextView? I want it to basically just scroll horizontally.

推荐答案

在某些情况下,当我试图压制不需要的UITextView滚动时,我发现将以下内容添加到UITextView委托中是有帮助的(这是一个UIScrollView委托方法,当然,UITextView继承自UIScrollView)。这可能适合你。

In some circumstances, when trying to clamp down on unwanted UITextView scrolling I have found it helpful to add something like the following to the UITextView delegate (this is a UIScrollView delegate method but, of course, UITextView inherits from UIScrollView). This might work for you.

- (void)scrollViewDidScroll:(id)scrollView
{
      CGPoint origin = [scrollView contentOffset]; 
      [scrollView setContentOffset:CGPointMake(origin.x, 0.0)];
}

scrollEnabled属性怎么样?将scrollEnabled属性设置为NO会阻止用户滚动(在两个方向上),但有时系统会将 setContentOffset:animated:消息发送到UITextView。 scrollEnabled属性适用于垂直和水平滚动。鉴于您的问题,您可能希望保持原样的scrollEnabled。

What about the scrollEnabled property? Setting the scrollEnabled property to NO stops the user from scrolling (in both directions), but there are occasions where the system sends setContentOffset:animated: messages to a UITextView. The scrollEnabled property applies to both vertical and horizontal scrolling. Given your question, you might want to leave scrollEnabled as is.

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

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