I am changing content offset programically with:
tableView.contentOffset.y += 100
This works well when the tableview is not scrolling at all. But when there is a scrolling animation, or when user is scrolling then it is reverted.
I've noticed UICollectionView allows you to keep the animation, and user interaction and move the scroll view with contentOffset, but I am not able to use UICollectionView.
Any ideas how can I change tableview's contentOffset even during user scrolling?
Swift playground:
https://gist.github.com/patryk-sredzinski/8f7111acbe7b1a65406463f70866b0b9.js
(inserting rows on top, changing the offset to keep user at the same cells, but whenever user scrolls on tableview, these offset changes breaks)
Related
How to change UITableView's scroll indicator's color? I just need to set it's color. Don't propose change it's style to black or white.
There is not a public API for doing that. Any recommendation that would be given would be likely to be broken when Apple makes changes to the underlying structure of the scroll view.
That does not, however, preclude you from creating your own scroll indicator from scratch. I needed to do this in a particular use case where a scroll indicator needed to be visible at all times, not just when the user was touching the scroll view.
You can have your custom scroll indicator view and position it where it needs to be based upon the content offset of the scroll view and its scroll indicator insets. Adding a handler in scrollViewDidScroll: would then allow you to correctly position it and take advantage of any inertia that the scroll view has.
You can even contract the size of the scroll indicator view based on how far the user has scrolled beyond the content size of the scroll view, to give the same effect of bouncing that Apple's implementation has.
i got a tableview and as a header i use amongst other things a scrollview.
All work ok in terms of scrolling apart from the fact that when i scroll down (or up) the tableview the scrollview "loses" the x,y coordinates.
for example if i scroll the scrollview on the headerview right to left (or vice versa) then the scrollOffset.x gets a value.
if i start scrolling the tableview then this value goes back to zero (although the scrollview doesnt lose the paging). If i go back to the scrollview and start scrolling again the scrollOffset.x gets its correct value again.
Anyway to "keep" the scrollOffset.x value when i scroll the tableview?
thanks
Considering that a tableView is a scrollView subclassed it seems like the problem is that scrollOffset.x is set by whichever scrollView you're currently scrolling inside of. Try adding tags to your table view and scroll view and add a variable to keep up with the scrollOffset.x for only the scrollView in your header.
I have uitableview scrolling upwards when keyboardWillShow event occurs. tableview is 320x148 and placed at the bottom of the uiview. When a user selects the first uitextfield, nsnotifcation is fired and moves the textfield accordingly.
My problem is, I have a label and logo in the background (uiview) that i want to see move upwards with the "event". I can do this with an animation, but it's not the desired effect.
My guess is to somehow make uiview move with uitableview somehow. Hope that makes sense.
Humm, i think you could put your UITableView inside a UIScrollView. When the UITableView scrolls, you could do the same to the UIScrollView behind..
I've got this question. In my app I have many cells. When user clicks on something I'm loading VC and pushing it. To indicate this behaviour I'm displaying a subview which informs that now application is loading. Problem is, when user scrolls down and taps on cell my subview still is on the top of the tableView thus user isn't seeing it.
I need to change frame of my subview so my user can see it. I want this frame to be the center of the current view. How I can do that?
Fore example: My content is 800 pixels worth of height, now I'm displaying at 400 pixels subview with specific information about loading. When my user scrolls down to a cell that is at 2400 pixels, I'm still displaying subview at 400 pixels and thus it is unviewable by user.
I was trying to calculate new frame.origin.y by checking y of a cell that is tapped. Problem is the cell at 2400 pixels could be the first cell user is seeing or the last one, so how I can get the middle of the screen?
Edited with some screens:
When I select first time:
When I select after scrolling down big time:
What it looks like you have done here is added the loading view as a subview to the UIScrollView. You need to add the loading viewController into the parentView after the scrollview.
If this cant be done because your viewController is a subclass of UIScrollview, change it to a regular UIViewController subclass but implement the scrollView protocols and then do as i have said above. Other than that you would have to map the frame of the loading ViewController to the offset on the scrollView-not a good idea.
Let's say, i have two tableview inside a scrollview. After i scrolled up & down tableview1, and then touch and swipe to scroll the scrollview horizontally to tableview2, i want tableview2 to have the same vertical (up & down) position as tableview1. is there any way to achieve that?
thanks
You can put code in the UITableViews' viewWillDisplay: methods that grabs the other table view's scroll position (called a "content offset" in scroll view parlance) and calls setContentOffset:animated:. This way, whenever either scroll view will appear on the screen, it will automatically scroll to the other view's position.