UIWebView in A UIscrollView - ios

I'm trying to add a UIWebView in a UIScrollView in storyBoard. I disabled the scrolling for the webView and enabled it for the scrollView . Since there are others views in the scroll view, i don't want to split the parent view.
But my problem is , the webView takes a static height even though I didn't set a height constraint for either of them (the scrollView and webView).
This means that the webView content didn't exceed its canvas(then its extra content got cut) and the scroll view didn't have extra space so it is not scrollable too .

What best I understood with your question I am trying to answer.
You have problem that after stopping web view scrolling you are not able to view web view contents. So you can do two things,
1) As your scroll view is having other subviews also,don't stop web view's scrolling but set its frame constrains so that with in a frame size you are able to view all web view content.
2) You can place web view in the bottom of scroll view and according to web view content set scroll view's content size. Set web view's bottom constrain to 0 with its parent so that there is no need to set web view's frame again and again.

Related

Why there is no possibility of scrollview scrolled when added contents dynamically.?

I am using scroll view. In my scenario, When contents are added dynamically in content view of scroll view. The view height must be increased automatically and content is added to the bottom with scrolling functionality. I tried the following. There is no particular way of scroll functionality. I don't know why scrolling is much complicated in iOS. Why scroll view not work the way like table view scrolling, table view taking any number of amount and scrolls. Finding youtube videos too not working as it has fixed height in advance .
Inside your scrollview you must add a UIView. Add a height constraint to the UIView and programatically change the height of the UIView depending on the content you are adding to this UIView. This scrollview will work if the height is large.

ScrollView is Not Appearing

Reference: Add a ScrollView to existing View
I inserted a scroll view into an existing view and now my page is not appearing and I am not sure how to fix this. My scroll view is under the view so I do not understand why it is not displaying.
With auto-layout, the UIScrollView needs to be able to calculate its content size using the available constraints. This is often best accomplished by adding a UIView in the scroll view to act as the content view, rather than directly embedding UIControl subclasses. The content view can then be constrained to be equal width and/or equal height to the parent view of the scroll view. The variable height/width (depending on the scroll direction) of the content view can be calculated by fully constraining the widgets it contains.

UIScrollView pushes content off the page

I'm using Xcode 7 and Swift 2.
I currently have the following structure for my app scene:
Scene -> View -> Stack View
The problem is that I've run out of space vertically, so I want to throw the Stack View into a Scroll View. When I do so however, the content gets pushed off the page horizontally. I have no idea why as without the scroll view everything fits flush within the screen. I haven't added any additional constraints.
Any ideas?
The whole point of a scroll view is that it fits to its content and allows you to scroll to it. So, if you don't constraint the content it'll take whatever size it naturally wants.
So, basically, you need to constrain the width of the content to be the same as the width of the scroll view so that it will grow vertically based on its intrinsic requirements. i.e. set the width of the scroll view and the stack view to be equal.
So it turns out that you need a content view (which is a regular uiview) first, so the final structure is
View -> Scroll View -> Content View -> Stack View
Now here's the critical part: You need to set an equal width constraint with the Content View to the View, not the Scroll View. The scroll view doesn't care about the size of your layout as you see it in Xcode, so you need to constrain everything inside of the scroll view to something outside of the scroll view. The stack view's constraints are four 0s to the content view (I could probably just have the stack view do the content view's job, but it works so I'm not gonna mess with it for now)
Step 5 of this link provided by Nick above gave me the idea

UIScrollview Height dynamic based on views ios

I'm writing an ios application, which has child views (like fragments or subviews) which are placing in a simple UIView in a UIViewController and the height of UIView is approx 300px. Im just loading subviews in UIView, however every subview has its own content that may not be fit in 300px thus uiscrollview cannot got though out the last view.
My problem is, Im unable to solve the scroll view content in order to scroll from parent UIViewController along whith its child view controller subviews, as the subviews are longer than 300px and thus uiscrollview is unable to get te last element.
I tried to to give static scrollview.contentSize.height = 1000 and hence the scroll view can scroll below the screen but im unable to click on the later views as it seems uiscrollview is unable to read that element.
My question is, how can i assign dynamic uiscrollview height assuming that im using autolayout in my uiviewcontroller and I want to calculate scroll height according to children based in my UIViewController. Im using swift 2.0 and autolayout in storyboard.
Your constraints should be like,
scrollview - top,bottom,leading,trailing
view (content view) - top,bottom,leading,trailing,fix height and horizontally center in container
and add your all other stuff in that view. you will got desired result. it will scroll in small screen size then content view and will not scroll for bigger screen then content view.
second thing you need to increase height of your content view as more subviews add. your content view's height should be equal to all subview's height and spacing
After this setup if you unable to scroll then check content view's bottom constraint's constant in size inspector. make it zero (if unable to scroll then only).
hope this will help :)

IOS : Make entire view scrollable, not only subview

I have a viewController in which I have a scrollView in which I have 3 views. This is a scheme :
ScrollView (UIScrollView)
Header (UIView)
TabBar (UIView)
Container (UIView in which I load a ViewController)
The main problem is that, in my container (in which there is a view controller), I have a collectionView (which can scroll) but I want my entire scrollView to scroll (not only my container).
So this is what I have :
And this is what I want :
Anyone can help me with this ?
I just solved this problem for my own project. Assuming you are using storyboards, I made the UIView a child of UITableView and made the UITableView extend the full viewport of the device.
Since UITableView implements UIScrollView you get full screen scrolling of your content.
General Rule your parent view has to implement UIScrollView and extend the full screen to get viewport vertical scrolling.
To do this, if you are not using auto layout or if you are adding views to container programmatically, you must manually set collection view frame to match its content size after you load some data on it. If you are using auto layout, you should create height constraint outlet and set its constant value based on collection view content size, again after loading data on it
You should set the frame of the container view to match the height of the view controller that it is loaded in it and set the contentsize of the scroolview based on the container height.
A scrollview will scroll only if its contents are bigger than its frame. This applies to the parent scrollview as well as the child scrollview.
Here in your case, for the parent scrollview to scroll its contents (Header, Tabbar & container) together must have greater height than its parent. The child scrollview (container) is already scrolling because its contents (a view controller) has greater height than its parent.
I have made both scroll views to scroll:
(1) The parent scrollview - by increasing the height of the child scrollview so that it extends below the main view controller's frame. The child scrollview is one of the contents of the main scrollview.
(2) The child scrollview - Setting a large content inside it so that it is bigger than its parent. I have used a long UIImage as its content.
Also, I have used autolayout and pinned the contents to the scrollviews' sides by adding constraints.
Hope this helps.
This is how it scrolls: Scrolling of UIScrollView inside another

Resources