Issue with Autolayout and StackView while using ScrollView - ios

I a trying to create a UIScrollView that fits exactly the contents of its subviews. I do this with a StackView and the scroll view's height is determined by how much content there is in the stack view. Within the stack views, there are views that contain an UIImageView and a UITextView
The UIScrollView starts below the title view, however every time I want to add another view (which it should scroll when the content is bigger than the actual frame) there is an issue with the scroll view's Y position. This works perfectly if I only add UILabels and UITextFields, using the same procedure
How can I do it so I can programmatically add views on the stack view that includes an UIImageView and a UITextView, just as the View Controller with labels and textfields does.
You can download my app project at the following url
https://github.com/francisc112/DescriptionWithImageApp.git

Instead of a scroll view why don't you use a table view and create a custom cell with the stackview and its contents inside the cell and you can dequeue the same cell for adding multiple information.

I was not able to open your project
So I Tried opening your StoryBoard and Re-Viewing your constraints Applied , here is what I have Done Please check in following Link
Link - https://drive.google.com/file/d/1D-dzKsSqpx7dWsI5fYRdAfCMY_vENoIR/view?usp=sharing
View Hierarchy
Note - For such output I will prefer using a TableView instead of StackView as Same output can easily be achieved using TableView

Related

How to make a Horizontal and vertical scrolling TableView in iOS using storyboard?

here is my design structure
I was wondering about creating a horizontal and vertical scrolling tableview. I have tried a tableview inside a scrollview but I failed miserably. What to do?
I use swift4 but I wanted to do in storyboard.
The nature of content is like an excel sheet with lots of horizontal and vertical scrolling rows and columns of data.
Actually you can do this using a hack. Put the tableView inside a scrollView. Then you should give a dynamic width to the tableView by specifying a width in storyboard for tableView or any child view of that scrollView(So we get the horizontal scrolling).You have to adjust some constraints depending on your requirement
Mine worked fine but as many users have said try a collection View if its easy
Note. There is a default scrollView within a tableView, So adjust your height of tableView in a way so the scrollView of tableView work and not the parent scrollView, while scrolling from top to bottom
Instead of using TableView try using collection view, there you can use horizontal and vertical scrolling using storyboard?
Try to use collectionview instead of tableview.
If your requirement demands use of tableview anyhow, then you can use tableview within scrollview.
In tableview within scrollview approach, you need to distinguish your parent scrollview as well as tableview's scrollview. Try to differentiate parent scrollview and tableview's scrollview with different tags. Because both scrollview will call delegate methods of viewcontroller, if implemented. Just check tag of scrollview in all delegate methods of scrollview and perform action accordingly.
As per my understaing you want a view which you want vertical scroll view and horizontal inside it.
So here my suggestion is to use UITABLEVIEW for vertical scrolling and UICOLLECTIONVIEW for horizontal scrolling inside tableview
Both will work fine

Multipage UICollectionView with View

I am trying to create a collection view layout similar to the one used by Twitter and Product Hunt. I want to have a horizontal collection view to tab between data while also maintaining vertical scrolling in the tab I am in. I do not want to just change the datasource that is loaded into the UICollectionView. I have tried several different layouts but none of them have been successful.
Right now, I have a UIViewController with a UICollectionView & UIImageView object inside of it. The UIImageView's size is (3/8) of the UIViewController's frame and begins at (0,0). The UICollectionView's frame is equal to the UIViewController's frame but the cv is offset to be below UIImageView & its size is equal to the size of the UIViewController's view. The (1) cell inside the UICollectionView has a UICollectionView inside of it -- this can be configured with the data you want (multiple cells). This layout works fine for a single datasource.
However, when you want to have multiple datasources accessed by scrolling horizontally the layout breaks down. You have to change the flow layout of the outermost UICollectionView to horizontal. When you do this, you get a layout error because the size of the collection view is larger than than the view and you cannot scroll vertically.
If you reference the image I provided, I think you can infer what the desired layout should behave like. You should be able to access the other datasource by horizontal scrolling but also be able to scroll the current collection view full screen and not have it fixed to the bottom of the UIImageView. I tried adding logic to the scrollview delegate methods but that didn't work either. Thanks]2

UITableView inside UIScrollView - Cell not clickable

I have a problem with a UITableView not detecting touches.
In an iPhone-only app, I have a UIViewController, which containts:
UIScrollView
UIView (let's say a content view)
Some labels
UITableView (last)
The labels have a dynamic height, because they contain some text that I must retrive from the web, so I'm using auto layout.
I'm setting the content size of the UIScrollView inside the viewDidLayoutSubviews method, and I'm doing this by summing UITableView.frame.origin.y and its height.
Here comes the problem: when the labels contain only some words and the UITableView does not exceed the iPhone screen size, everything works ok. But when they grow, and the UITableView gets pushed down, when I scroll down I can't click on the cell anymore. Also, if when loading the view the table is half visible and half not, I can click the visible cells, but if I scroll down, I can't click the others.
I'm using swift 2 and Xcode 7.
Here is an example:
Clickable:
Unclickable:
Do the following thing:
yourView.clipToBounds = true
Now, if UITableView does not appears means your UIView is not same bigger to hold down UITableView.
Make sure that your UIView height is bigger to hold the contents in it and then try to tap on it.
Updated:
If you are using AutoLayout, then do the following thing.
Give the fix height to UIView
Take the outlet of height constraint of UIView
Now, in viewDidLayoutSubviews change the constraint of UIView to UITableView contentSize height.
self.heightConstraint = self.tableView.contentSize.height
Let me know, if this helps!
Adding some info to the #Rémy Virin's answer here:
From Apple Documentation, you shouldn't embed a UITableViewinside a UIScrollView.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Addition:Solution Since you want to scroll the content above table also, the one solution is place a Header View for the Table and place the Content over there to make it Scroll along the Table View.
If you use Autolayout, no need to specify contentSize to UIScrollView as it will automatically expand by taking the height of its subview.
In your case, increase the height of the Base UIView (content view as mentioned by you) which holds the tableView when the tableView height increases.
UITableView becomes unresponsive when it extends below its container view.

Hiding labels in iOS without breaking the view

I know we can use UIStackView in iOS9, but I'm not able to get rid of iOS8 at the moment, so I was wondering if is it possible to hide some labels inside a UIView (plain UIView, UIScrollView and UITableViewCell) and keep the rest of the visible labels "stacked".
Basically I've got some labels "stacked" vertically and pinned to each other by autolayout. If I hide any of them I get an empty space where the label was placed in interface builder.
I've managed to emulate the stackView's behavior using OAStackview, Following these steps:
Subclass ViewController using a UIScrollView and a OAStackView property.
Put the stack view inside the scroll view
Set constraints for these properties programatically
Add a bunch of custom labels to the stack view.

UITableView and Another View inside ScrollView

I have UITableView and UIView(used to show image slideshow) inside UIScrollView. The tableview is dynamic and i want to automatically adjust height of table view to show all the cells(and disable scrolling of tableview) and scrollview should show both slideshow and tableview and could be scrollable, I know how to do this with code but i want to know if is possible to do in Interface builder(without using iOS6 auto layout) using previous(iOS5 and early) autoresize method in the xcode size inspecter tab(see image)
I think this is hard to do only using interface builder.
You can set your objects via interface builder. But for maintaing scrolling conditions you need to do it programmatically. Also for table view height to be dynamic you need to be done programmatically.

Resources