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.
Related
I have a WKWebview that I basically want to override the zooming behavior for. I want to scale up the font, so what I have right now is a UIView on top of the WKWebview that I've added a UIPinchGestureRecognizer to that does some evalutateJavascript call on the webview. However, now the Webview doesn't receive tapping or scrolling events as I believe the overlay view is capturing them. Is there a way to send it down to the webview? These are all in a single VC with outlets to both the webview and the overlay view. I wanted to override the behvaior directly for the WKWebview but I can't seem to get it to work.
Basically I know if you need to deliver gesture event to other responders, just set the pinchGestureRecognizer.cancelsTouchesInView = false
I am currently using a UIScrollView to store 2 tables side by side, similar to how Pinterest does for its Activity page. However, when I tap on the 2nd table and access a new UIViewController, going back would reset the contentOffset, hence, I'm back on the 1st table which is wrong.
Am I able to lock the contentOffset or is there other ways to do this?
Thanks in advance.
Try this in the UIViewController that contains the UIScrollView:
self.automaticallyAdjustsScrollViewInsets = NO;
I've been researching how to use a UIWebView embedded in a UIScrollView for a while now and cant seem to find an easy fix to my problem. I'm using a UIWebView because a UITextView, although allowing hyperlinks, does not allow you to change the link color from the standard blue apple sets.
But using a UIWebView introduces another problem: It blocks the UIScrollView it is embedded in from handling scroll events because a UIWebView handles these events within its own private implementation.
Although this allows me to use its embedded links, the UIWebView absorbs the touch events which doesn't allow me to scroll up/down when dragging within the UIWebView itself. I worked around this problem by placing a transparent UIView overlay exactly over the UIWebView, intercepting the touch events that it receives, and resigning it as first responder so that the UIScrollView that they are both subviews of can handle the scrolling appropriately.
Now, however, I can't seem to think of solution to the new problem this introduces: I can't click on the links within my UIWebView that is right under the UIView Overlay.
What is the best way to forward touch events to a UIWebView that is right underneath my transparent UIView in order to trigger my UIWebView's delegate method 'webView:shouldStartLoadWithRequest:navigationType:' for tapping on links?
FYI from UIWebView API doc:
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.
Back to the question,
UIWebView has property called scrollView, try doing:
webView.scrollView.scrollEnable = NO;
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.
I'm trying to create an app that will have an interface similar to the Mail app on the iPhone. When you view an email message on the built-in Mail app, it displays sender/receiver information in addition to the subject in an area before the message. I was thinking of using a WebView for the message portion, but I can't figure out a way to have some custom view appear above the WebView while still within the same ScrollView.
What is the best way to implement this? To me the best option seems to be generating the "custom view" at the top in HTML/CSS, and simply appending the message's HTML afterward. I've looked at trying to put a WebView with another view inside a ScrollView, but it seems to go against Apple's design guidelines.
Any ideas or suggestions would be great.
Thanks,
Thomas
I don't hink it is against Apple guidelines.
What I'd do in your case is the following.
First create the scroll view
Place inside it your fixed height header (with subject, etc...)
Then place inside the scrollview a webView with an y offset of your headers height.
After the webView is done loading call [webView sizeToFit]; (wich resizes the view trying not to crop subViews)
Maybe you'll have to set the y offset again (frame.origin.y=offset)
And then set the scrollview content size to the sum of the two heights:
scrollView.contentSize=CGSizeMake(width, headerView.frame.size.height + webview.frame.size.height);
I'm not really confident with what [webView sizeToFit] is going to do. I've read you can also use [webView sizeThatFits:CGSizeZero]; . It will apparently return the needed size for the webView.
The you would simply have to change the webviews frame size to the return value of that function and use the same contentsize statement as before.
Hope this helped
PS: I think it's a bad idea to use html as a replacement for views. It's much slower and it takes initial time to load. The only use I've found to it is for displaying formatted text.