【问题标题】:UITextView Inside UIScrollView Scrolling Parent as Text is EnteredUITextView Inside UIScrollView Scrolling Parent as Text is Entered
【发布时间】:2012-06-29 20:02:18
【问题描述】:

我有一个包含UITextViewUIScrollView。当文本输入到UITextView 时,UIScrollView 将滚动以确保文本在内容框架中完全可见。我不想要这个。

我已禁用 UIScrollView 上的滚动,但这没有任何效果。有谁知道如何阻止这个?可以在此处找到示例项目:http://cl.ly/1P1u3y302r3q1f1C063K

谢谢!

【问题讨论】:

    标签: iphone objective-c ios xcode ipad


    【解决方案1】:

    UITextView 也有类似的问题。似乎scrollEnabled 属性不会取消自动滚动。我通过覆盖setContentOffset: 方法获得了solved
    以下preventScrolling 标志可能会有所帮助:

    @interface MyScrollView : UIScrollView
    @property (nonatomic, assign) BOOL preventScrolling;
    @end
    
    @implementation MyScrollView 
    @synthesize preventScrolling;
    -(void) setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
    {
        if(!self.preventScrolling) {
            [super setContentOffset:contentOffset animated:animated];
        }
    }
    @end
    

    【讨论】:

    • 最好覆盖scrollRectToVisible:animated:(当它的文本属性发生变化时从UITextView发送到UIScrollView的消息)什么都不做,这样你就不需要额外的属性了。
    【解决方案2】:

    你设置了错误的 contentSize: 滚动视图....

    始终根据滚动视图内的内容设置内容大小,如果内容的高度和宽度大于滚动视图的高度和宽度,则仅增加内容大小,否则将其与滚动视图的宽度和高度相同

    [self.mainScrollView setContentSize:CGSizeMake(4096, 4096)];
    

    而不是它把这个 contentsize:

    [self.mainScrollView setContentSize:CGSizeMake(mainScrollView.frame.size.width, mainScrollView.frame.size.height)];
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-26
      • 2019-04-05
      • 2022-11-09
      • 2015-03-26
      • 1970-01-01
      • 2017-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多