WKWebView pinch-to-zoom in iOS10 - ios

I encountered a problem that after I upgraded my phone to iOS 10 beta 3, when I zoom a WKWebView in my app, the zooming function not only zoom the content of the web page but also the page itself.
See the image I attached. WKWebView that fails to zoom correctly. I set the background color of the WKWebView to blue, when I pinch to zoom out the view, the page(container?) itself also zoomed out, causing unfavorable result. It does not happen in iOS9. When I do the same thing, the blue background does not show.
The web page is written in AngularJS and the Graph lib is d3js.
The related code are as below.
-(void) reloadWebPage{
[activityIndicator startAnimating];
NSString *indexToPath = [self getIndexHtmlPath];
NSURL *fileUrl = [NSURL fileURLWithPath:indexToPath];
NSURL *absoluteUrl = fileUrl.absoluteURL;
if(currentGroup == nil){
currentGroup = #"0";
}
NSString *absoluteString = [[absoluteUrl absoluteString] stringByAppendingFormat:#"%#%#", #"?currentGroup=", currentGroup];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:absoluteString] ];
[webView loadRequest:request];
}
- (void)createWebView{
WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
[config.userContentController addScriptMessageHandler:self name:#"interOp"];
webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:config];
[webView setBackgroundColor:[UIColor blueColor]];
[webView setNavigationDelegate:self];
[webView setUIDelegate:self];
}
I have no clue where is the problem? Is it in Objective C,iOS10 or in Javascript?
Please suggest, How can I resolve this problem?
Thank you

Ok, I resolved this problem by disabling zooming and scrolling in WKWebView.
webView.scrollView.scrollEnabled = false;
- (UIView*) viewForZoomingInScrollView:(UIScrollView *)scrollView{
return nil;
}
After these code are added, the WKWebView itself no longer zooming and moving while the nodes move and zoom normally.
It seems the problem somewhat related to Disable magnification gesture in WKWebView, but
I still don't know what caused the change from iOS9 to iOS10. But it seems to work for me.

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

Using PanGesture with GoogleVR Panorama

I need to display 360 images on iOS devices.
I chose GoogleVR to do this (https://developers.google.com/vr/) and I'm using the GVRPanoramaView. (https://developers.google.com/vr/ios/vr-view)
_panoView = [[GVRPanoramaView alloc] initWithFrame:self.view.bounds];
[_panoView loadImage:[UIImage imageNamed:#"VRTest.jpg"]];
[self.view addSubview:_panoView];
It works well, the image is displayed and I'm able to see all around using the device gyroscope.
I'd like to be able to move across the image using pan gesture but I can't find a way to achieve this using the given SDK.
Is it even possible ? I did not find anything in the documentation saying it's not ... but didn't find any solution either ...
In the end I used the web version of the same framework ... that handle both gyroscope and pan gesture (but only around y axis) ...
https://developers.google.com/vr/concepts/vrview-web
I embedded the framework in my app to have it local (I want to be able to load offline image)
https://github.com/google/vrview
Then I used a simple webview :
UIWebView *webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
// Path depends of your bundle
NSString *indexPath = [[NSBundle mainBundle] pathForResource:#"vrview/index" ofType:#"html"];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:#"VRTest" ofType:#"jpg"];
// load the local framework with the local image
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#?image=%#&is_stereo=false", indexPath, imagePath]]]];
// Disable scroll because of collision with pan gesture
webview.scrollView.scrollEnabled = NO;
[self.view addSubview:webview];

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];

how to fit 255 width table in UIWebView

I am trying to view the web-page in UIWebView in iOS. Below is the link I am trying to view.
http://almaktab.com/forms/flight.html
The problem is width of table is 255px and when I open this in webview, it covers only half screen which looks odd. Below is the code I am using for viewing web page in UIWebView.
-(void)openWebPage:(NSString*)address {
NSURL*url=[NSURL URLWithString:address];
NSURLRequest*request=[NSURLRequest requestWithURL:url];
myWebView.scalesPageToFit = YES;
myWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
myWebView.contentMode = UIViewContentModeScaleAspectFit;
myWebView.autoresizesSubviews = YES;
[myWebView loadRequest:request];
[myWebView setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
}
I want to stretch this webview so that form can fit for whole page.
I know solution for this would be width=100%, but client don't want to do any changes in their website now. Client asked to do changes in iOS only.
Any idea how this can be get done.
Screenshot (myWebView.scalesPageToFit = YES;)
Screenshot (myWebView.scalesPageToFit = NO;)
Try:
webView.scalesPageToFit = NO;
And in webViewDidFinishLoad:
[view stringByEvaluatingJavaScriptFromString:#"document.getElementById('table3').width='100%'"];
You should have not use AutoresizingMask.

Displaying a .doc file with custom margins

This piece of code dispalys a document in a scrollable UIWebView:
- (void)viewDidLoad
{
[super viewDidLoad];
_myWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 760)];
NSURL *myUrl = [NSURL URLWithString:#"http://pathToDoc/myDoc.doc"];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];
[_myWebView loadRequest:myRequest];
[self.view addSubview:_myWebView];
}
This works fine except when trying to display a landscape document which has been created with custom margins which are smaller than standard.
The result is the contents of the right-hand edge of the document are chopped off.
Is there any way to display the whole document?
Well, after several months of frustration with this (can barely believe how long it took!), it turned out to need only a single line of code to solve the problem.
_documentWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Add that just after the last line and suddenly all is well in the world.

Resources