How to move UIWebView scroll to UIScrollView? (Conditionally)

I have a UIWebView inside a UIScrollView .

This idea is to create more reading space on the screen when the user browses the web page up - by scrolling the UIScrollView up until the toolbar is visible, and obviously when the toolbars are actually visible, scroll web page to display more content on the page.

The IPhone Safari browser performs exactly the same functionality.

see the screenshot (first) for the default behavior, I get - I think, because: the scrolling message is consumed by the webview, since the touch / scroll happens directly in the webview area.

what I would like to do here is a software solution when to forward the "up scroll" to UIScrollivew and when not to.

Any advice on getting around this would be so helpful. Thanks!!

enter image description here

enter image description here

+7
source share
3 answers
0
source

a reference to the UIWebView class prevents the implementation of UIWebView in UIScrollView:

Important: you must not embed UIWebView or UITableView objects in UIScrollView Objects. If you do this, unexpected behavior may occur because touch events for two objects can be mixed and mistakenly processed.

However, I suppose you still want to implement your function ;-)

Idea 1 . Do not embed a UIWebView in a UIScrollView, instead run javascript using the UIWebView method stringByEvaluatingJavaScriptFromString: by changing the DOM to add the toolbar below. If necessary, you can call the objective-c code from any buttons pressed on the toolbar by registering some custom URL schemes.

Idea 2 . Do not embed a UIWebView in a UIScrollView, but in a regular UIView. Based on the Vignesh clause, listen for the internal scrollView web scrollViewDidScroll: through the delegate, checking the heights of contentOffset and contentSize each time the callback is called. Once they are equal, it means that you have reached the point. Once this happens, you can animate the toolbar frame to the โ€œenterโ€ containing the UIView and โ€œpushโ€ the webView frame.

Idea 3 . Ignore Apple's recommendation and insert UIWebView into UIScrollView. Based on the Vignesh clause, listen for the internal scrollView web scrollViewDidScroll: through the delegate, checking the heights of contentOffset and contentSize each time the callback is called. Once they are equal, it means that you have reached the point. Once this happens, set the userInteractionEnabled property for the webView to NO and set it to YES on the scrollView that contains the webView and toolbar. We hope that the scrolling will continue smoothly enough. Of course, you should listen to the containing scroll view in the same way to determine when userInteractionEnabled needs to be returned.

A variant of this idea would be to simply set userInteractionEnabled to NO for the webView, but set the height of the webView frame according to its contentSize, and also increase the contentSize of the containing scrollView accordingly.

Both options have the disadvantage that in some cases you wonโ€™t be able to do such things as clicking on the links :-( But maybe this is good enough for your business. At least in the first version it is not so bad.

+2
source

You can add the search query and uiwebview to UIscrollview one below the other. To get the content offset when scrolling through the webview, you can use the following code snippet.

 UIScrollView* currentScrollView; for (UIView* subView in testWebView.subviews) { if ([subView isKindOfClass:[UIScrollView class]]) { currentScrollView = (UIScrollView*)subView; currentScrollView.delegate = (id)self; } } 

Now you can change the offset value of the scrollview baseline to the offset value that you get from the scrollview doscroll delegate method.

0
source

All Articles