I have an iOS project which needs to "control" the UIScrollview's scrolling. UIScrollview needs to know current scroll position, also needs to limit scroll, and "transfer" the scroll to scroll the UITableView inside it.
I tried to google, apple dev, ... but no luck :(
I have to handle UIPanRecognizer by myself, but it isn't "smooth" like UIScrollview default scrolling (scroll accelerator).
Anyone have an idea?
Related
I want my app to have a view that can scroll even when there isn't always content to scroll to. For instance, the Wifi tab in settings is always scrollable. Is this a UIScrollView?
I'm using Storyboard, not SwiftUI by the way.
Thanks in advance for any suggestions!
I've tried using a UIScrollView but I think what I'm trying to achieve is different.
I think you're looking for the UIScrollView's alwaysBounceVertical property:
If the value of this property is true and bounces is true, the scroll view allows vertical dragging even if the content is smaller than the bounds of the scroll view. The default value is false.
The Settings app is using UITableView in "group" mode for most screens. The little bit of scrolling you can do even when there is little content is referred to as "bounce".
UIScrollView can also be used (UITableView extends UIScrollView). The bounce actually comes from the scroll view. You can enable the bounces property.
I've been trying to replicate this effect for a couple days which was inspired by Tumblr.
I've previously asked questions on here with different approaches of the same problem but to no avail. I'm just curious as to how the engineers at Tumblr created a horizontal collection view, with two vertical collection views, and is able to scroll down without affecting the view above (without resetting the position of the view when you scroll vertically in a different tab).
Header Views
I tried this, but the header view was isolated and I had to scroll to the right to see the collectionView cells. This did not work.
Changing the topLayoutConstraint constant of my UIView (not cv header) with respect to the contentOffSet of the vertical collectionView.
This almost got the effect I wanted, except that when I scrolled horizontally, there was a huge gap between my collection view and if I scrolled in that new tab, the UIView would appear again because, again, topLayoutConstraint gets scrolled up depending on the contentOffSet of my vertical collectionView contentOffset.
Changing the position of the UICollectionView frame, and scrolling the super view up simultaneously with NSNotificationCenter.
Alas, this method did the same as method #2, except that the vertical collection view cells scrolled faster than the super view.
I ran out of options to make this work so I will show you in detail what's attempted to be replicated (also note the scroll bar on the right):
Note when I scroll down the first tab. I switch, and then scroll down further. Originally, as I've said, there would be a gap between the second main CV, and when I scrolled, the view would reposition as if were scrolling up again. On here, the view on top keeps going up. So I'm curious as to what method Tumblr engineers used to do this. UICollectionView inside UIScrollView? Other suggestions?
I believe there is no UICollectionView involved. It looks like UIPageViewController and each its page is a UITableView.
Perhaps the UIPageViewController sits in a UITableView as well - the header also moves up when you scroll. This main table has only one cell (and a header) which is occupied by the UIPageViewController.
Hope it helps.
I'm working on a application where I have a UITableView inside a UIScrollview.
The TableView will display current games players are in, its inside a UIScrollView. I dynamically add cells to the UITableView for each game, but when I scroll the UIScrollView, the tableview inside it snaps back to its size set in the storybuilder.
This is because of autolayout, when I disable it, it doesn't happen anymore. However I do like autolayout for other views in my app. So my question is, how can I fix this problem?
Maybe someone can help me get on the right track.
Thanks
EDIT
I think I must explain my situation more, I will use an image where I can display what is happening
Explanation
Before and after scrolling.
As you can see I use the scrollview because there can be many games, so you'll have to scroll down to see them all. The TableView is just to hold the data, scrolling is disabled on that. After scrolling the TableView that says "JOUW BEURT" snaps back to its size set in the Storybuilder. This is because of auto layout like I said, but I don't know how to fix this.
You shouldn't put a tableview inside a scrollview as a tableview itself contains a scrollview and causes issues just like you are seeing when you have a scrollview inside a scrollview.
Remove the scrollview and this should fix your issue. If you are wanting to put content above the tableview or where you scroll down to view the tableview cells etc, consider adding a tableview header view that is added above the tableview.
Why did you place UITableView inside UIScrollView?
Check below
Check your constraints of UITableView and UIScrollView
Placing UITableView inside UIScrollView is somewhat strange
EDIT
You will just need to remove the scrollview and enable scrolling feature of the tableview. that will fix it
UITableView is already a subclass of
UIScrollView
I have the following layout
So it's basically a scroll view that occupies whole screen. Content size is set to triple-width and same height. Inside the scroll view - there is container view and three table views - one per page. Only middle table view is visible initially.
This allows me to use scroll view horizontal scrolling to navigate between the tables and vertical scrolling inside the middle table.
I know that Apple doesn't really recommend putting UITableView inside UIScrollView, but in this particular case I don't know how to implement it differently, and until iOS8 everything was working fine.
UIScrollView would not recognize any vertical scrolling (since content height was equal to scroll view height) and these gestures were passed directly to UITableView.
But starting in iOS8 - this getting broken. UIScrollView would allow some vertical scrolling and basically intercept scrolling gestures sent to UITableView.
I created a simple project that works fine in iOS7 but is broken in iOS8. Anybody has any idea how to fix this problem?
Link to the project: https://dl.dropboxusercontent.com/u/6402890/TablePaging.zip
I haven't been able to solve this and as I mentioned in comments had to re-write logic using built-in UIPageViewController class.
If I change the Class of your ScrollView in Interface Builder to UIScrollView, it fixes part of the problem. Now just the UITableView goes up and down, and I go left-and-right, but haven't gotten rid of the space at the top.
I want to implement a paging UIScrollView that will scroll in both directions (vertically, and horizontally). The default behaviour of UIScrollView is to be one, or the other. Not both.
Is it possible to implement a UIScrollView that would allow paging in both directions? For example, the user would be able to scroll left and up for the previous page with paging in UIScrollView, right and down for the next page.
I can use UIScrollView to implement scrolling horizontally with paging but I can't see how UIScrollView can be scrolled in both directions while paging. How could I implement this behaviour? UIScrollView ? or CAScrollLayer? or anything else?
Any suggestion are appreciated.
You seem to be talking about two different things here: scrolling and paging.
Scrolling is just flicking around to move the screen's viewport over a view that is larger than the screen itself. Normally you set this up by giving a UIScrollView a subview that is larger than it, and setting the UIScrollView's contentSize to the size of the larger thing.
There's nothing magic about it. If contentSize is taller than the UIScrollView's size, the scroll view will scroll vertically. If contentSize is wider, it will scroll horizontally. If contentSize is both taller and wider, then you'll scroll both vertically and horizontally.
Paging is a different matter. To know how to make it so "you can scroll left and up for the previous page", we'll need to know what a page looks like in your program, how it's represented, etc. From the small description you're giving, I think UIScrollView probably isn't the way to go. Instead, look into UIPanGestureRecognizer and some sort of animated transition between views?
But if that doesn't help, you'll need to give us some more details to work with.