Force to not reload a uiwebview - ios

I'm working in a news feed.
I have a uiwebview who load an url and show all the news. The problem is, that page has a button: "Load more news" at the bottom of the web page. So, when the user press there, the page load more news.
The problem happen, when we have a video in one of our news. Because, when the user press over "load more news" the uiwebview refresh the page and the scroll go back to the top of position.
So... my question is: There are a way to solve this?
Can we stop a refresh?
Thanks.
Regards

You could save the position of the webview before the load more news button is tapped in a variable
CGPoint scrollOffset = self.webView.scrollView.contentOffset;
And you can later restore its position by setting the same scrollOffset to the webview again:
[self.webView.scrollView setContentOffset:scrollOffset];

You can try to handle UIWebView delegate -shouldStartRequest and return NO in your case.

Related

iOS UIPageViewController page control getting out of sync

Whenever I swipe the page controller and tap the UIPageControl at the bottom in the opposite direction of the swipe at the same time, the page that is currently being displayed and the page number in the pageControl will be out of sync.
Has anyone ever had this weird issue and solved it?
Let me know if you need any additional info.
Just checked out the docs for UIPageControl. I never realized this myself, but you can use page controls for input:
When a user taps a page control to move to the next or previous page,
the control sends the UIControlEventValueChanged event for handling by
the delegate. The delegate can then evaluate the currentPage property
to determine the page to display. The page control advances only one
page in either direction.
My suggestion would be to either disable the page control or update your app to respond to input on it. Setting userInteractionEnabled to false on my page control resolved the problem for me.

UIWebView prevents UITableView to scroll

I have a cell in my UITableView with a UIWebView. The problem is that if you swipe on the UIWebView you swipe throughout the internet page, and not the table view. Since the web view has a hight of 500, it is possible that the user is stuck in the web view. Does anyone have any ideas in how to solve the problem?
Beginning with iOS 5, there is a scrollView property on UIWebView, so you can just do the following on your web view:
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
Then you should be able to scroll just fine. No need to disable interaction on the web view, unless you don't want the user to be able to interact with it at all.
If the user does not need to interact with the webview, you can set webview.userInteractionEnabled to NO.
If they need to interact with it, but don't need to scroll, you can set webview.scrollView.scrollEnabled to NO
Either of those solutions should allow scrolling to pass through to the tableView.
If they need to scroll the webview, I'd suggest rethinking your UI. AFAIK, Apple advises against having nested scrollviews.

iOS release a touch event to load data into a UIWebview

I have a UIWebview that is scrollable and loads text from an array. They're previous and next buttons to allow the user to get the last or next content.
If a user holds down the scrollable content of the UIWebview and taps next, the text in the UIWebview will not load the next data until the user releases their finger from the screen.
How to I cancel the touch from the screen momentarily when the user taps the previous or next buttons.
Thanks :-)
Usually, switching off and back on a gesture will force it to cancel.
Edit: I was on my cellphone before, so I'll just add more details to my answer.
If your using iOS 5 and up, you can probably try something like this in your button action (I'm not on a Mac right now so I didn't test):
- (IBAction)yourAction:(id)sender {
[webView.scrollView setScrollEnabled:NO];
[webView.scrollView setScrollEnabled:YES];
//The rest of your code...
}
The reason I'm saying iOS 5 and up is because before iOS 5, the scrollView of a UIWebView wasn't exposed. If you're not using iOS 5, you have to resort to iterating through the subviews of your webView to find a UIScrollView.

Content Editable UIWebView scrolls and overlaps over the button/images of uiview in iOS

I have a view with few buttons and UIWebView which loaded content editable HTML.
In UIWebView i am inserting images/Canvas using both native and javascript functionality.
Since the WebView is editable whenever webview is clicked keyboard comes up. Now when we are inserting/editing a image/canvas keyboard should hide. So for that i am checking for tap event, getting the id of the element at that position and hiding the keyboard if that is a image/canvas using [webview endEditing:YES];.
Now the problem what i am facing is that if i add 2-3 images and then clicks on the webview, webview starts moving from its position and overlaps the button/images kept at the uiview. So the button are not visible and i am not able to perform the actions related to that.
Issue resolved. I was using some kind of animation when the keyboard was show/hidden. Once i removed that uiwebview doesn't moves.

UIWebview GestureRecognizer for showing a toolbar

I have a Webview (inside a view) and a toolbar which is hidden most of the time.
This is quite common behaviour for ipad magazines:
Tapping on the page will hide and display the toolbar, but the toolbar is hidden by default.
I am using shouldRecognizeSimultaneouslyWithGestureRecognizer
The behaviour right now does this:
- If the user taps the page (webview) it toggles the toolbar state using gesture recognizer
- if the user taps the page and there is an interactive element such as a weblink within the UIWebview, it responds to that interactive link but ALSO toggles the toolbar.
The desired behaviour is this:
- if the user taps the page on a non interactive area, it toggles the toolbar state
- if the user taps the page on an interactive area it ONLY responds to the webview interaction and does NOT toggle the toolbar.
Note there is an almost identical question here:
Gesture recognition with UIWebView
Even though it is marked as resolved if you read it through you will see the solution did not work for the poster and he is still getting a dual response when he (and I) want an either or response. I did try posting a follow up question but that was deleted probably because the moderator believed it was resolved
If the UIWebView, for whatever reason, catches the touch, you're not going to be able to get the UIGestureRecognizer callback as well. My only recomendation is to make whatever happens in the website when you tap on something execute some javascript, and then catch that Javascript. You can take this as an example.

Resources