Note that there are some explanatory texts on larger screens.

plurals
  1. POUIScrollView gets disabled in one direction - iOS
    text
    copied!<p>I have a UIScrollView with no vertical scrolling, and on which I force a particular offset (only x) in case the offset tries to become less that that particular offset. I use <code>setContentOffset:animated:</code> function, with <code>animated</code> argument as <code>YES</code>. The offset is forced correctly. </p> <p>After I force the offset, 'sometimes' scrolling in the direction opposite to the initial scroll direction gets blocked. Say, I was scrolling with finger pan from left to right, and forced it to some offset, then I can't scroll from right to left anymore.</p> <p>But the catch is, if I make any tap on the screen, the scrolling starts happening. I am unable to pan, but if I tap the screen, or tap any button, scrolling starts working. If I try to call the button press method programatically after, say 5 seconds of forcing the offset, then it doesn't work. It seems that I need to touch the screen somehow..</p> <p>I checked the values of <code>contentOffset</code>, <code>contentSize</code>, they seem fine.</p> <p>PS: there are times when <code>scrollViewDidEndScrollingAnimation:</code> method is not called after forcing the offset, but that is not necessarily the issue.</p> <p><strong>Edit:</strong> Actually, this thing happens when I take the scroll view beyond the threshold offset using my fingers, and keep panning left. At the threshold point, panning stops, but the next time I try to scroll, it doesn't pan. (i.e., I don't give a jerk to go beyond the threshold).</p> <p><strong>Edit:</strong> One more possible loophole: I make <code>scrollEnabled</code> equal to <code>NO</code> just before forcing the new offfset, and just after giving the command to set the new offset, I set it back to <code>YES</code>. I needs to be done so that if I try to scroll the scrollview with a jerk, it doesn't scroll away to the left while trying to set the new offset, since paging is enabled. </p> <p><strong>Edit:</strong> Could it be because I set <code>scrollEnabled</code> to <code>NO</code> while actually scrolling using touch? I do enable it later, but maybe that is some issue...</p> <p><strong>Important Edit:</strong> If I long press on the scrollView, and then try to move, scroll view starts scrolling!</p> <p><strong>Edit:</strong> This code is in <code>scrollViewDidScroll:</code></p> <pre><code>if ((theScrollView.contentOffset.x &lt; theScrollView.frame.size.width) &amp;&amp; [currentlyDisplayedVC isEqual:VC1]) { //if this is not done, and this call happens when VC3 //is visible a bit too much, scrollView scrolls till VC3. scrollView.scrollEnabled = NO; [scrollView setContentOffset:CGPointMake(scrollView.frame.size.width, 0) animated:YES]; scrollView.scrollEnabled = YES; //this is done so that this block is not reached everytime during scroll animation. currentlyDisplayedVC = VC2; } </code></pre> <p>Then in <code>scrollViewDidEndWithANimation:</code> I add <code>[self VC2reached]</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload