what does animation means in scrollViewDidScroll? - ios

In the doc, I found
scrollViewDidScroll:
If you scroll in code without animation, you will receive this message once.
scroll without animation and scroll with animation, what's the difference?

It means that the view will scroll to that point with an animation (same as if you were using your finger), or it will jump to it directly.
For example, imagine that the user sees the top of the scroll, and you call scroll to the bottom with animation, the user will see all the scroll going down to the bottom, instead of just appearing there.

Related

UIKit collection view, strange behavior (accessing/scrolling cells)

So I recently implemented a collection view in my app, and I got a bug that I can't seem to solve, searched it and saw no threads about it.
If I have my cursor/finger over the cells i can't scroll through my collection view i need select a "empty" area to scroll.
Second strange Behavior I came across is that I can't directly touch a cell. I need some sort of swipe gesture over it to trigger the code when a cell is selected.
If I go to my collection view on my storyboard and select Delays Content Touches and Cancellable Content Touches in the scrollview section, the collection view scrolls just fine but if I put my finger/cursor over a cell with these option enabled I can't access any cells anymore.
This completely confuses me.
and thank you for reading/considering this thread.
Let's see what your two properties do.
delaysContentTouches: If the value of this property is true, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value is false , the scroll view immediately calls touchesShouldBegin(_:with:in:). The default value is true.
canCancelContentTouches: If the value of this property is true and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled(_:with:) message and the scroll view handles the touch as a scroll. If the value of this property is false, the scroll view does not scroll regardless of finger movement once the content view starts tracking.
First, you set delaysContentTouches to false. So the scrollview immediately calls the content view's touch handling methods, allowing it to handle the touch. Obviously, the scroll view won't start scrolling right away because of this, even if you drag.
Second, you also set canCancelContentTouches to false. But if the scroll view isn't allowed to "take over" touches that the content already handles (by cancelling them), it is never able to start scrolling later on either. So if your touch hits a content view, there is no possible way for the scroll view to start scrolling: it isn't allowed to scroll right away because it isn't allowed to delay the content touches, and it can't start scrolling later because it can't cancel the content touches.
I don't know what happens within your cells, not sure what code you put in there. However, you should probably allow your tableview to both delay touches (that means that your cell won't handle swipes that are cancelled immediately anyway because they were intended to be scroll gestures), and to cancel content touches (that means that when you touch down and don't release, you can still start a scroll gesture after a cell became highlighted).
i had the same problem when touching a cell, the problem was that I'm using more than one UIGesture without adding ".cancelsTouchesInView = false" for each one
so if you're using a UIGesture just add Your_Gesture.cancelsTouchesInView = false
and you should be able to access your cells

Stop `UICollectionViewCell` disappearing after `UICollectionView` bounds change

I have a UICollectionView that animates its bounds when a user lifts their finger from the screen. The collection view either grows or shrinks based on how much the user scrolled. This works great if the user lifts their finger up whilst the UICollectionView is stationary however if they flick the scroll view unexpected results happen.
As you can see the UICollectionViewCell disappears before it has a chance the naturally scroll away.
I am using AutoLayout and therefore animating the constraints of the collection view calling [self.view layoutIfNeeded]; I want to suggest that the animation is getting in the way of the scrolling judging by the way the scrollbar moves, it seems to set the UICollectionView to its projected end contentOffset then animate the slide up.
I would like to know why this effect is happening? And any tips on how to fix it!

Scroll a view except a part of it

I want a screen with scroll, and I want to scroll until a part of the view. When I reach this, this part will be fixed on the top and you can go on scrolling. In the image:
You begin scrolling until the buttons part, then, the buttons stay fixed in the top and you can scroll more. It's like the spotify app effect in the lists, more or less, if you know it.
Thank you in advance
You could probably achieve this by implementing the -scrollViewDidScroll: method in your scroll view's delegate. When the view scrolls, check the offset to see if the button is visible. If it is, and if it's close to the correct position, you could remove it from the scroll view and position it above the scroll view in the position you want.

horizontal scrolling of a scrollView in a scrollView - small problem

i have a scrollView that fits the whole screen. In that View i show some UIImages that scroll horizontally. Like in the PageControl Project from Apple.
Then, when the user taps the screen, i fade in a scrollView at the bottom with some other images. Also horizontally scrolling. Like in the ScrollView Project from Apple.
My problem is, that when i come to the end of the scrollView which was faded in, the upper scrollView also starts to drag. How can i stop that during activation of the second scrollView?
Redraw the frame limits on your first scrollView when the second enters the screen. That way, your touches won't respond to both views. This means you need a container-view to keep both views seperated from each other.
Then you just rescale it back whenever your second scrollView disappears.
Edit: or disable scroll in your first scrollview while the second is open.

UIScrollView scrolling to bottom when UITextField text changes

As it is set up now, I have two UITextViews inside of a UIScrollView. The point of this is that the UITextViews themselves don't scroll, they just get larger (their contentsize) as more text is added. The UIScrollView handles all of the scrolling up and down of the view regardless of how much text there is (think similar to Mail.app where the subject view is above the message view, etc). That said, I've ran into a problem now. When I programmatically add text to my UITextView (in this code, bodyText), the UIScrollView automatically scrolls to the bottom for some reason.
To add the text I just do:
NSRange selectedRange = [bodyText selectedRange];
NSString *selectedText = [bodyText.text substringWithRange:selectedRange];
bodyText.text = [bodyText.text stringByReplacingCharactersInRange:selectedRange withString:[NSString stringWithFormat:#"<b>%#</b>", selectedText]];
So, for instance, if I had 2000 pixels vertically of text and was currently scrolled to position 400 and then added text somewhere around there, the UIScrollView would then go all the way down to 2000.
I've tried to stop it via subclassing UISCrollView and overriding -setContentOffset, but that freezes all scrolling then.
My question is, why does it scroll all the way to the bottom in the first place? The text is added when the user clicks a button somewhere else on the screen, and the scrolling has nothing to do with any finger drags or anything.
In Scroll View Programming Guide you get:
Making a rectangle visible
It is also possible to scroll a
rectangular area so that it is
visible. This is especially useful
when an application needs to display a
control that is currently outside the
visible area into the visible view.
The scrollRectToVisible:animated:
method scrolls the specified rectangle
so that it is just visible inside the
scroll view. If the animated parameter
is YES, the rectangle is scrolled into
view at a constant pace. As with
setContentOffset:animated:, if
animation is disabled, the delegate is
sent a single scrollViewDidScroll:
message. If animation is enabled, the
delegate is sent a series of
scrollViewDidScroll: messages as
animation progresses. In the case of
scrollRectToVisible:animated: the
scroll view’s tracking and dragging
properties are also NO.
If animation is enabled for
scrollRectToVisible:animated:, the
delegate receives a
scrollViewDidEndScrollingAnimation:
message, providing notification that
the scroll view has arrived at the
specified location and animation is
complete.
So maybe you can use this functionality to lock the visibility on your UITextView.

Resources