Using PanGesture with GoogleVR Panorama - ios

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

Related

WKWebView pinch-to-zoom in iOS10

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.

How to get a video to play in UIWebView (video is in a ALAsset group)?

Okay maybe the headline is somehow disturbing, I hope to state this so you can understand my problem.
So I have a scrollview which has paging enabled. I want to build something like iOS Photo App.
I load the photos and videos which are on the device via ALAsset and store them in a group.
Now i want to present each object on a separate subview of the scrollview.
For the pictures it is working fine. But for videos I cant make it work.
Here is what i did and what did not work:
First:
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
NSString *embedHTML = [NSString stringWithFormat: #"<html><head><style></style></head><body>\
<video id='video_with_controls' width=\"%0.0f\" height=\"%0.0f\" controls>\
<source src='%#' type='video/MOV'/></video><ul>\
</body></html>", self.mainScrollView.frame.size.width, self.mainScrollView.frame.size.height, [assetRepresentation url]];
[webView loadHTMLString:embedHTML baseURL:nil];
then:
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
NSString* embedHTML = [NSString stringWithFormat:#"<video controls> <source src=\"%#\"> </video>", [assetRepresentation url];
[webView loadHTMLString:embedHTML baseURL:nil];
Also I tried to store it in NSData first and then load it from there, but that causes memory problems and wont work.
Any help is highly appreciated!
Edit: As I think UIWebView is the thing that matches the iOS App visually at most, I want to use this and not for example the MPMoviePlayer .. if I am wrong there I would be glad to know how / what else looks like the original App
I guess the video url is local thats why its not working in UiWebView
so the solution would be this:
in delegate method webviewdidstartload,set up MPmovieplayer controller to play inside a UiView and yes it will look like original app as you will be playing it in a view
something like this:
Add MPMoviePlayerController's view to a UIView
When you movie file is located locale you must set the baseURL to your MainBundle and put the full path in the "src"-tag.

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

iOS : jump to a specific slide in ppt

I've one ppt file locally that I'm opening with UIWebView with below code, file having 10 slides, now with the requirement, I want to jump to a specific slide, something like if I want to directly jump to slide#3 then how to do it with this code?
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:#"ppt"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
//open ppt into UIWebView like,
[self loadDocument:#"newone" inView:self.myWebview];
I searched here, and found this, they are doing
Link to http://www.whatever.com/hello.ppt#4 for slide 4 to be opened initially.
but my ppt file is saved into document directory (locally) within my app.
Any suggestion?
You can set the offset of UIWebview ScrollView.
[[webView scrollView] setContentOffset:CGPointMake(widht, height) animated:YES];
Find height of one slide in current zoom scale. Multiply it with four as forth page to open initially. and put in above code with point CGPointMake(0, heightYouCalculated)

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