UIWebView contentInset without extra height at bottom - ios

I'm creating a view controller that uses a web view which slides behind the navigation bar and status bar. To do this, I'm setting the webView.scrollView.contentInset property to have a top inset of 64.
However, this doesn't shrink the amount of area the web view wants to take up, so if a page is less than a screenful, it has 64 px of white space at the bottom to scroll through. The web views are in a vertical UIPageViewController, so this disrupts paging. Is there some way to get rid of this extra space?

Have you tried something like adjusting the webview's scrollview content insets? Example:
webView.scrollView.contentInset = UIEdgeInsetsMake(0, 0,64, 0)

It sounds like what you need is to adjust the webView.scrollView.contentSize and adjust the height by 64. You may need to provide more information about how it slides behind the nav bar and status bar to help me answer this. I would take a look at this section of the Scroll View Programming Guide:
http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/CreatingBasicScrollViews/CreatingBasicScrollViews.html

Change the clipsToBounds.
webView.clipsToBounds = NO;
This will make its content visible outside its frame, so set its frame like normal, right under the navigation bar. The navigation bar will be translucent and you will see its content under it.

Don't forget to disable Autolayout for the web view!

I've sort of made an end-run around this problem by disabling scrolling on short pages. Basically, I use -stringByEvaluatingJavaScriptFromString: to run some JavaScript inside the page that walks down from document.body and computes the position of the bottom of the bottommost element. (document.body itself is always at least as large as the viewport, so I can't look at its size.) Then, back in Objective-C-land, I compare that to the height of the web view (less the inset), and if it's less, I disable scrolling. This is not a perfect solution, but it covers the worst symptoms.
If someone can come up with a better solution than this, I'd love to hear about it! Either way, I can't award the bounty to myself, so someone will be getting it.

Related

Table Views that don't take up the whole screen, within a stack view

I'm having problems trying to implement a layout for my app. Whenever I use tableviews, it wants to take up as much space as possible. I'm trying to have (from top to bottom) a tableview with two rows, a text field, and a horizontal stack view rooted to the bottom with two buttons. Something like this:
Mockup
My issue is that constraining this has been a bit of a nightmare. At the moment I actually have the view looking just like this, but its hard coded with the top constraint of the tableview being inset by 400. I need a way for this to be flexible, as when I click on the textfield, i'm going to have that adjust to the top of the keyboard, along with the tableview above it.
At the moment I currently have the TableView within a View, which is in a StackView with the textfield and bottom stack view with the buttons. How can I set up the constraints in such a way that the entire stack seems to appear rooted to the bottom of the screen?
I'm sorry if this is a broad question, it's more of a 'How should I go about this' rather than 'How can I do this' kind of question. I should mention I'm doing this programatically too, using SnapKit for the constraints.
Thanks all!
Fixed by rethinking the whole thing an simplifying. Took the table view out of the stack, put that and the stack view in. Then the problem was my original one, the cells being stuck to the top of the screen and constraining not changing it at all.
So I flipped the table view using
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)
And doing the same to the two cells to flip them back to normal orientation. Now the view is perfect! Hope this helps anyone in the future

UIScrollView & AutoLayout - UIScrollView Over scrolling (showing excessive whitespace at bottom)

I have a login page with a bunch of elements on it:
UIScrollView
Content View (UIView)
Email Text Field
Password Text Field
Login Button
Etc.
I need my app to run perfectly in both portrait and landscape orientations so I began setting up the different constraints to get AutoLayout working properly. I finally have all my UI elements in the right positions for both Portrait and Landscape, but the issue is that my scroll view scrolls too much and leaves a lot of empty white space at the bottom of the view when fully scrolled. I would like to fix this and keep things tight but I am not sure why. It's clearly the contentSize of the scrollview that is being set too large for the y value but I do not want to fix this with a workaround programmatically as I'm sure there should be the "correct" fix out there.
I've attached screenshots of the login page normal and fully scrolled (portrait and landscape) to help further understand.
Any help would be greatly appreciated. Thanks!
To adjust the height of scroll view, you need to do these two things:-
In the size inspector of scroll view, change the intrinsic size to "PlaceHolder".
Make sure you have added enough constraints that height of scroll view can be calculated. Since the contents in your scroll view are of static height, you can simply add a height constraint to your scroll view.
I'm not a 100% sure of this, but it could be that the view extends over the nav bar, causing the scrollview to have a much larger height than it should. IF that is the case, then autolayout-ing your view cause elements to be displayed everywhere else, other than the places you want them to be.
You'll need to disable Extends Under Top Bars in the attributes inspector.
I too had problem with scrollview my problem was that in iOS8 the scrollview was leaving some white space from top. I got crazy, finally I saw the solution by Ali Awais in this post and it fixed it
Here is the solution and link by Ali
I faced the same issue in iOS 8, following is solution I found: - Select View Contoller (in storybord) in which you have added the scroll view - In "Property Inspector" in "Layout" section un-check "Adjust Scroll View Insets"
White space scroll view
-anoop

Is there a way to make something truly free scrolling div (any direction) on iOs webview

I want a div that can be dragged any direction and is about 4x width and 4x height of the screen.
I set the body height and width, and you can scroll it diagonally some of the time, but other times when you go to scroll it will go only straight vertically or straight horizontally. It seems to be when you start scrolling straight up, it sticks that way. Is this normal for scrolling in an oversized webview div, or is there something else that might explain this?
This is on an iPad, with a body set to width:4000px and height:3000px.
The iPhone's tendency to scroll exactly horizontally or exactly vertically is intentional, and it's usually a useful feature: if you're reading a tall column of text that could scroll horizontally, it's nice to be able to scroll down without worrying about accidentally moving the view from side to side as you go. As far as I'm aware there's no way to turn this behavior off.
there is a property name directionalLockEnabled that get a bool
in scrollView class.
this will do the trick:
theWebView.scrollView.directionalLockEnabled = NO;

AS3: Increase size of scroll bar

This my be a really simple question but I have googled so hard looking for an answer. I have a datagrid which displays a long list of information. Its an iOS app so the input is touch and the scroll bar is tiny. How can I increase its size for easier use?
Thanks =)
Feathers is as3 solution to mobile ui : http://feathersui.com
These scrollbars can be targeted by DataGridInstance.verticalScrollBar and DataGridInstance.horizontalScrollBar. These are actually ScrollBar instances so you can use the .setSize() method or .width and .height setters to resize these.
However, the documentation indicates:
Note: If you use the setSize() method, you can change only the width of a horizontal scroll bar or the height of a vertical scroll bar. At the time of authoring you can set the height of a horizontal scroll bar or the width of a vertical scroll bar, but the values will be reset when the movie is published. Only the dimension of a scroll bar that corresponds to its length can be changed.
So I'm afraid it's not an option with the built-in component.
Use code like this:
dataGrid.scroller.verticalScrollBar.scaleX = 2;

is it possible to move the UIScrollView indicator from the right side to the left?

I realize I can rotate the cells and move the indicator by displaying the scroll view "upside down" but that requires a lot of other rotations, and manipulating of information to make the Table scroll properly.
Thanks for the time
Actually, it is possible by changing the scrollIndicatorInsets property to restrict the indicator to a small area on the left side:
tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0,0,0,tableView.bounds.size.width-10);
I like Jeremy Jay's solution (though I haven't tested it), but just to thoroughly explore the idea... here's another that might be worth trying (though it's also untested):
Use two scroll views.
One scroll view (we'll call this the "real" one) contains your content but has its indicators hidden. Another scroll view contains no content but has its contentSize set to match that of the "real" scroll view's. When the "real" scroll view's contentOffset changes (as observed via delegate messages), change the "fake" scroll view's offset to match. (Check out the scroll views session from WWDC 2012 for more on the idea of using a scroll view without a content view.)
In theory (again, I haven't tested this), you now have a scroll indicator view that's separate from your original scroll view, and you can place it wherever you like in relation to the original. Layer it on top of the original and move/size it so it occupies a narrow sliver on the left, and you have a left-side scroll indicator. (Alternately, layer it atop the original and flip it horizontally with an affine transform.) Put it somewhere else entirely to take your UI on a trip to crazy town. (Or don't.) Make sure you make it ignore touches if it's layered on top, though.
A quick way to achieve this (if you're not using row actions) without having to calculate insets or messing with additional table views, would be to transform the table view across the Y-axis (flip) and then transform the cells back when you get them.
tableView.transform = CGAffineTransformMakeScale(1, -1);
and then
cell.transform = CGAffineTransformMakeScale(1, -1);

Resources