I’m writing a app which has a bookshelf view like iBooks.
The problem now is: I can drag and drop a book from on place to another.But how do I make these happen at the same time when I drag book to the bottom of the scrollview:
- make the scrollview scroll down
- keep the book follow my finger
- place the other books at the right place with animation like moving apps in springboard
I know there’s an AQGridView in Github, but it seems that the springboard demo doesn’t support scroll and move at the same time.(I already set scrollEnable to YES)
I ll give you my solution, but since the entire thing is quite big i’ll just give you the relevant snippets.
Also, mind you I use a gesture recognizer for the dragging (UILongPressGestureRecognizer) as that is how the user initiates dragging in my app, by keeping his finger pressed on the object. So each subview you can drag around has its own UILongPressGestureRecognizer assigned to it, and the target/selector of that recognizer is in another class which manages both the scrollview and the subviews.
here is the target of the gesture recognizer:
The things that are relevant for you:
This is the code
This thing only does horizontal scrolling, but handling vertical would be quite similar. What it does is:
your dragged view moves along so we compensate for that with an opposite offset of its center.
Hopefully this can help you.