ScrollViews and Segmented controller - ios

This is really odd, but I have a segmented controller and both of the views have a scroll view. So when you click on one half of the segmented controller that view has a scroll view, and the other half also has a scroll view. For some bizarre reason only one of the views will scroll. I need them both to scroll. Does this made sense?

First in the viewDidLoad I added a subview for both of them. Then I added an if else statement with .isHidden and that works beautifully.

Related

UICollectionView Scrolling the ViewController

Im trying to implement a CollectionView inside my viewController.
And it works just fine.
The problem Im having is that the CollectionView scrolls inside the Parent controller.
I wish to make that if you scroll the collection view - the whole view is scrolled and not just the collection view bit.
I tried disabling scrolling on the Collection View but then nothing is scrolling anymore.
So how would I go about setting the collection view, so that once you scroll on it the whole page scrolls and not just the collection view scrolling inside the parent view controller?
It should be simple, and you've done one right thing already.
Disable scrolling of your collectionView (or tableView, in the future just in case you'll use it, they're basically the same).
Add your collectionView (or tableView) inside a scrollView.
That scrollView is of course in your controller's view.
Make sure every constraints are set properly.
You might need to get the size of your collectionView (say height), and set that height value to the constraint height of your collectionView.
These answers of mine in the past should help you:
https://stackoverflow.com/a/52657995/3231194
https://stackoverflow.com/a/54211275/3231194
https://stackoverflow.com/a/53971539/3231194
Voila. The only scrolling enabled is your scrollView that contains your collectionView (or tableView).

Scrollview won't scroll all the way down

I have a scroll view which works fine. Almost. I'm building in Any/Any. The problem is that the scroll view won't scroll past the view controller. I have a switch that is mostly in the view controller window, but the rest is off the box (not really sure how to describe it; it's in the view in the scroll view, but the view is longer than the view controller so part of it is hidden).
The scroll view will scroll down until it hits the part where the view controller would end if you were looking at it in Xcode. There is some more stuff under the switch (labels and another switch). To view these you have to forcefully scroll down. Xcode shows no constraint errors (little red circle with white arrow).
Hopefully this makes sense
A ScrollView needs to know the height and width of the content it is holding in order to know how much to scroll and which direction. Here is a quick read on how ScrollViews work in iOS: https://www.objc.io/issues/3-views/scroll-view/
You can set this programmatically using the contentSize property, but this requires you to know and or calculate the contentSize, which is pretty tedious in most cases.
The correct way of defining the contentSize in iOS is to define AutoLayout constraints in your View. Here is an excellent tutorial on doing just that:
https://www.natashatherobot.com/ios-autolayout-scrollview/

Page view constraints bug

I have set up a page view controller in swift with a scroll view and a view inside the scroll view. I made constraints for both of them but when I run the project on swiping left or right between the pages the view in the scroll view first comes a little bit smaller and then when the swipe is completed it expands.
Here is the problem:

animation not correct with implicit autolayout

I upload my demo code here:https://github.com/liuxuan30/Problems
The main problem is, I had a view which have a scroll view inside, and there is a label and collection view inside scroll view.
There will be a unread message button generated by code, when there is unread messages, the button will pop out, and I expect the animation: label and collection view will down-shift by the button's height.
When I test the animation without adding the button in subviews, animate as expected.
When I add the button in, it seems like the label and collection view's origin.Y up-shifted, and start the animation. Turning off auto layout will solve it, but I have to have auto layout. I tried to add constraints for all views, but the animation still not work out.
You can try comment out
[self.HomeScrollView addSubview:AlertView]; and self.UnreadAlertView.alpha = 1.0f; inside the code to see the animation.
Hope someone could figure out where i did wrong.
UICollectionView is already a subclass of UIScrollView. Embedding your collection view inside a scroll view may be what is causing problems with your animation.
Try removing your scroll view and just put your UIButton, UILabel, and UICollectionView inside your overarching view.

ios : tableview not appearing in subview of a scrollview

I have a scrollview with multiple views.Enabled horizontal scrolling.Each view contains a tableview.I have page control in scrollview. when i drag horizontally, the views are appearing without tableview except the first view. Please give me suggestions.
Make sure if setContentSize to your scrollview means scrollview content size is the size of your main view.
When you scroll to next view or if you scroll to view displayed for first time, make sure you reload table. You can implement his through delegate and protocols. For example, when you scroll to second view for first time, then controller should call some method on subview to reload its table.

Resources