UIWebView: Content get bigger when reload - ios

I'm having problem of UIWebView: I create a webview at the ViewDidLoad, and a button to reload the page, and everytime I click the webview download a new picture but the height get longer and longer (url gives random picture).
//Here is how I create it
pubTop = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 70)];
[pubTop loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:URL_PUB_LEVEL4]]];
[pubTop setScalesPageToFit:YES];
pubTop.scrollView.scrollEnabled = NO;
and I do reload by: [pubTop reload];
I need help please!!!

Related

Use WKWebView to display link pdf cause invisible keyboard view

I try to use WKWebView to display a link pdf, it works, but when I check the view hierarchy, I found this cause an invisible keyboard window, and an auto layout issue. because this a system issue, I do not know how to fix it.
this is my code:
self.webView = [[WKWebView alloc]initWithFrame:self.view.bounds configuration:configuration];
_webView.backgroundColor = [UIColor clearColor];
_webView.allowsBackForwardNavigationGestures =YES;
_webView.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal;
[self.view addSubview:self.webView];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[#"https://xxxxxxx.pdf" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]]];
[_webView loadRequest:request];
this is the Debug view Hierarchy:
enter image description here
this is the auto layout issue:
enter image description here

UIPDFPageRenderOperation object 0x12de5fcf0 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug

I'm adding some PDF links to my UIWebView and every time one loads and I make a scroll gesture, I get this error: “UIPDFPageRenderOperation object 0x14acaca10 overreleased while already deallocating; break on objc_overrelease_during_dealloc_error to debug”.
So, is the UIPDF is being deallocated while I try to scroll?
Anyone have a hint?
If I scroll really fast then I even get a crash. Still happens on iOs 9.3.3.
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height - 20)];
NSURL *url = [NSURL fileURLWithPath:#"/Users/userName/Desktop/bigIcd.pdf"];
[webView loadFileURL:url allowingReadAccessToURL:url];
[self.view addSubview:webView];

Cropping a UIWebView in Xcode

I have a UIWebView, but don't want to display anything at the top of the page, down to about 50 pixels. I need a way to crop the UIWebView so that users cannot see what is above that 50 pixel margin. How can I go about doing this effectivly?
UIWebview contains a UIScrollView which is used to display HTML content. Changing the conent offfset allow to change the page view... see example of google
/**
* basic webview boilerpoint
*/
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,
0,
CGRectGetWidth(self.view.frame),
CGRectGetHeight(self.view.frame))];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://google.co.uk"]]];
[self.view addSubview:webView];
/**
* disable bounces so users cannot scroll beyond content & set top offset by 100 to hide parts of website
*/
webView.scrollView.bounces = NO;
webView.scrollView.contentInset = UIEdgeInsetsMake(-100, 0, 0, 0);

Recieved memory warning issue in webview add inside UIScrollview?

I have tried to load 40 UIWebview in uiscrollview. user scroll more than 5. Recieved memory warning alert comes continuously, finally application quit.
How to manage this memory issue, please let me know.
Thanks in Advance
I tried this:
Description: Load one by one webview are added in UIScrollview because i have tried to load all webview using for loop single time but app crash in this for loop so doing add one by one process.
CGRect vFrame = self.view.frame;
UIWebView *wViewLocal = [[UIWebView alloc] initWithFrame:CGRectMake(vFrame.origin.x, vFrame.origin.y, vFrame.size.width, 900)];
wViewLocal.delegate = self;
wViewLocal.backgroundColor = [UIColor grayColor];
NSString *fileUrl = [[subSubChap objectAtIndex:selectedIndex] stringByReplacingOccurrencesOfString:#".htm" withString:#""];
[wViewLocal fileUrl baseURL:nil];
[wViewLocal setScalesPageToFit:YES];
[wViewLocal setContentMode:UIViewContentModeScaleToFill];
[wViewLocal setFrame:CGRectMake(selectedIndex*viewRect.size.width,0,768, 900)]; // here set X-Value each webview.
[wViewLocal setTag:selectedIndex];
[scroll_View addSubview:wViewLocal]; // Here i have add UIWebview
[self.array_MainObject addObject:wViewLocal]; // Here i have add all UIWebview in NSMutableArray for get particular webview info.
[wViewLocal release];

UIWebview full screen size

I am trying to display a pdf in a UIWebview using the entire screen of the device, except the status bar and top bar. So far, I created IBOutlet UIWebview *webview; in my .h file. I connected the webview in my storyboard and wrote the following code in my .m file:
- (void)viewDidLoad
{
[super viewDidLoad];
webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
webview.scalesPageToFit = YES;
webview.autoresizesSubviews = YES;
webview.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
[webview setBackgroundColor:[UIColor clearColor]];
NSString *path = [[NSBundle mainBundle] pathForResource:#"Chart" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webview loadRequest:request];
[self.view addSubview:webview];
}
The pdf displays correctly in my 3.5 inch, but in my 4 inch display, the bottom is cut off. This is even more noticeable when I rotate to landscape view. About 33% of the screen is not used at all. How can I fix this? I know it must have something to do with the UIWebview dimensions in my code above (webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];), but is there a better way to simply display the webview on the entire screen, without specifying a specific screen height and width?
One cheap thing to do would be to set the frame of the webview in overriding - (void)viewDidLayoutSubviews
- (void)viewDidLayoutSubviews {
webView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
the advantage of doing it here, is that the size and orientation of the view has already been determined here, and you can get an accurate measurement.
Using Auto Layout
Be sure the "Constrain to margins" option is not checked, all constrain values are 0:
And your webview is a first child of your main view:
Without Auto Layout
Change webview autosizing connections:
After a lot of headache dealing with compatibility of iOS6, 7 and different screen sizes, I use this one:
- (void)viewDidLoad {
[super viewDidLoad];
self.webview = [[UIWebView alloc] init];
// More setting your webview here
// Set webview to full screen
self.view = self.webview;
[self.webview loadRequest:aRequest];
}
I was able to get this working correctly for me by selecting the Reset to Suggested Constraints under the Resolve Auto Layout Issues menu.

Resources