I have a UIWebView that I am loading onto another view, everthing looks fine in portrait or landscape when rotating, however when I am in portrait and I zoom in slightly with pinch or double tap when I rotate from portrait to landscape the view dosnt fill completely with the uiwebview, there are about 10pxls on the right that turn black as outlined in this screen shot.
if you look carefully you can see the outline of the scroll indicator in the black, which segests this is part of the uiwebview?? if so then why dose it turn black in this area.
Also heres another screen shot of the webview scrolled up abit so you can see its part of the uiwebview...
This is how I am adding the view onto the detail view.
- (void)viewdidload
//..
//Load in FirstView
firstView = [[FirstMainViewController alloc] init];
firstView.view.frame = CGRectMake(0.0, 0.0, firstView.view.bounds.size.width, firstView.view.bounds.size.height);
firstView.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
firstView.view.backgroundColor = [UIColor whiteColor];
[self.view insertSubview:firstView.view belowSubview:actionTabBar];
//..
Try to set the background of the webView transparent (clearColor) and set it's opaque property to FALSE. Then make the background white in your html or simply have the view beneath the webView white.
I had the same problem, and simply setting opaque to NO fixed it. Didn't even have to change the background color, it works fine with the background color set to white.
I put in the line...
webView.scrollView.backgroundColor = UIColor.whiteColor()
webView is my #IBOutlet weak var webView: UIWebView!
Turn off WebKitDiskImageCacheEnabled and the black border goes away :
In applicationDidFinishLaunchingWithOptions add the following lines :
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:#"WebKitDiskImageCacheEnabled"];
[[NSUserDefaults standardUserDefaults] synchronize];
Related
I want to show a pop up window in my iPhone app whenever I receive a push notification through didRecieveRemoteNotification. Something like the windows shown in the image attached. I tried doing addSubview with my view controller, but it occupies the entire screen. How do I create the pop-ups?
Instead of adding a subview with dimensions of the screen {320x460}, create a view with smaller dimensions such as {100,100} and add rounded corners to them via the UIView layer properties
#import <QuartzCore/QuartzCore.h>
....
view.layer.cornerRadius = 5;
view.layer.masksToBounds = YES;
UPDATE: To achieve the background dim effect, contradicting to what I first suggested. Add your PopUp view to a view with a frame of the full screen dimensions {320,460}. You then apply a transparency color to it via the UIColor -colorWithWhite:alpha: method. Like below:
view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
I'm creating a UIWebView with a blank page using the following code.
- (void)loadView {
[super loadView];
UIWebView *wv = [[[UIWebView alloc] initWithFrame:self.view.bounds] autorelease];
wv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:wv];
}
When rotating the device from portrait to landscape or vice versa the page's content becomes bigger than the webview's bounds and black areas appear. What might be the problem?
It looks like self.view (the webview's parent view) may not have the correct autoresizing masks. A subview's autoresizing mask will only fill up to the container bounds. If the webview's parent view does not have it's autoresizing mask setup correctly, then the webview's autoresizing masks won't look correct, either. You seem to be setting up the webview properly (not using CGRectZero on initWithFrame without ever setting an initial size), so your current implementation should work barring nothing else has been setup funny in your view controller.
webView.scalesPageToFit = YES;
See also: UIWebView+SFHFStringMetrics
My app's main view has a uiwebview. It is white for a split second before it has time to render the HTML the app generates.
Is there a way to make the uiwebview black, or another color, before it renders? The flash of white isn't part of my plan for a smooth visual transition.
Objective-C or MonoTouch answers are fine, I am bi-lingual.
Another thing to try is to make the view transparent:
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
This causes additional compositing work, however, so you can reset these values to something more friendly for that after your web view loads, in webViewDidFinishLoad:.
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
webView.backgroundColor = [UIColor blackColor];
webView.opaque = YES;
}
One thing you can try is put a UIView with the color you want and position it above the UIWebView with the same width and height. Then in the webViewDidFinishLoad method, set the UIView to hidden.
I can't comment yet hence the answer.
#Steve, actually it's possible to do with storyboards.
Place a UIView under the UIWebView and:
// Can be set in the storyboard
bottomView.backgroundColor = [UIColor yellowColor];
webview.alpha = 0;
Keep in mind that a lot of page fetch stuff after being loaded via JS so you still can be left with a white page couple seconds after
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
webView.alpha = 1;
}
To add to Steve Madsen's answer (since I can't comment yet). If you instanced the UIWebView in Interface Builder, you wont be able to set alpha to 0.0, but what you can do is bring up the color picker to set a background color (white, black, gray, it doesnt matter), then set the opacity of that color to zero percent, and that works.
could you show me some algorithm or example code to display like that picture with or with out animation
thanks for all advise
Add a semi-transparent view (regular view with black background with opacity = 80) that will cover the entire screen (in IB or in code), add a UIActivityIndicator and a label to the semi-transparent view, set it hidden.
If you use the IB then you should also create IBOutlets for the semi-transparent view (loadingView) and for the activity indicator (loadingAnimationIndicator)...
Use the next methods to show / hide the "loading view":
- (void)showLoading {
[loadingAnimationIndicator startAnimating];
loadingView.hidden = NO;
}
- (void)hideLoading {
loadingView.hidden = YES;
[loadingAnimationIndicator stopAnimating];
}
I'm using a UIWebView with text in it. When the iPhone is rotated to landscape, text doesn't fill the now wider UIWebView width. I'm using P (paragraph) tags, which should not affect content filling landscape's width. The line breaks that are visible in portrait remain the same in landscape. In Interface Builder, I haven't changed anything. In the IB Inspector, Web View Size has all solid bars under AutoSizing, which means it should fill to the landscape width right?
Here is a tweak though not a good thing to do, and something should be handled by apple itself
As you've noticed that things workfine when WebView is initialized in portrait and then you turn it to landscape. So.. what you can do is always initialize your webview with portrait bounds, add a selector which calls back after 2~3 seconds and sets the frame of webView according to your requirement.
Now as the contents started loading when the frame size of your webview were according to portrait (say 320,460) so converting your webview to landscape will automatically adjust your web view if you have this line in your code
[webViewObjet_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
Below is the snippet of code
- (id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
webViewObjet_ = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
.....
}
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
.....
[self performSelector:#selector(chuss) withObject:nil afterDelay:3];
// call the function chuss after 3 second
}
- (void) chuss
{
webViewObjet_.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[webViewObjet setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}
Now tried around with the same problem, finally did it after looking detailed at "WhichWayIsUp"-Sample from Apple.
To keep it short:
1) Disable in the View Inspector the |--| and <-->
2) `switch the View Mode from the Webview to "Aspect Fill"
Et voila ;)
Keep the vibes,
Maniac
I have the same problem. Reloading does not work, the only thing that seems to help a bit is to add the following line to the code:
self.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth;
(I place it in the willAnimateFirstHalfOfRotationToInterfaceOrientation function)
It still keeps a small white margin at the right, but its far better than the default. Note: you should apply this on the self.view and not on the UIWebView instance, that won't work.
Waiting for a solution from Apple..
Pieter
This will sound strange, but it works:
If the UIWebView is inside a UINavigationController, it will all work just fine. I had the same problem, so I just wrapped it up in a UINavigationController and the problem was gone.
For some reason, UINavigationController makes rotations work like a charm.