It seems to me that my UIWebView is behind other views - ios

I am adding a new uiwebview in order to login.
One day(After updating to iOS9, but I think that this is not the reason) I failed to show this uiwebview.
So, what can I do to be sure, that my view is at the top ?
Is there any way to programmatically get it higher ?

(void)bringSubviewToFront:(UIView * _Nonnull)view
Use this on the superview of your UIWebView:
eg:
[self.view bringSubviewToFront:self.webView];

Related

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.

Stop UIView being dragged around screen

We are integrating a third party offer wall into our iOS phonegap app.
When we show the offerwall it gets added to the standard phonegap viewcontroller and shows over the top of our webview.
The problem with it is that people can drag the view all over the place so instead of just scrolling up and down in place. Which gives the effect show in the screenshot below:
What we want to achieve is being able to anchor this view so it can't be dragged around the app and can only be scrolled vertically.
In the integration code we have access to a UIView for the offerwall and the ViewController of the main app.
The offerwall is provided as a library so I don't have access to any of its code and can only deal with the UIView returned and the UIViewController I add it to. Other apps have managed to implement the view without horizontal scrolling
We are looking for code to apply to either the UIView or ViewController to prevent this.
Thanks
The offerwall view probably contains a UIScrollView that holds the actual content. You could try looping through all subviews and turn off scrolling on the first scroll view it finds:
for (UIView *view in offerwall.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView*)view;
scrollView.scrollEnabled = NO;
return;
}
}
This is definitely hacky, but if you don't have access to anything else from their code it might be your only option.
In the end the solution was quite simple. Turns out the offerwall was a UIWebView and in testing mode the offerwall page was rendering some elements that were overflowing the page hence the horizontal scrolling. In production mode the problem goes away

Loading a WebView with a specific offset

i'm building an Application that should load an html rendered webpage, it works but, as should be, it loads the view from the top of the page, what if i want it to load from a specific offset ? i've tryed to add the parameters ScrollX and ScrollY in the layout, but it just made the app crash... so how can i achieve such a behavior?
thanks in advance :)
You can set the contentOffset of your WEbView-
And the code will be like this -
[webView setContentOffset:CGPointMake(0,-20) animated:YES];

How to programmatically simulate a double-tap on a UIWebView?

My app has a UIWebView that displays HTML emails. If I zoom in on the content and then double-tap on it a couple of times, the email content eventually gets resized so that it all fits on the screen again.
I'd like to programmatically reproduce this resizing behavior (I want to be able to call a function that re-scales the content so that it all fits on the screen); calling sizeToFit on the web view does not seem to have any effect.
If you know the CGRect you want to scale it to, then you can use,
- (void)zoomToRect:(CGRect)rect animated:(BOOL)animated
As UIWebView is scrollable, So I guess you should be able to do this.
Apparently your UIWebView should have an iVar named scrollView. So, if your UIWebView object name is webView. just do something like, below code might not be 100% syntactically correct. But you must have got the idea.
[webView.scrollView zoomToRect:CGMakeRect(0,0,0,0) animated:YES];

Trouble figuring out how to add a custom view above WebView within the same ScrollView

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.

Resources