Hello everyone!
I’m working on a project that use HTML5 to draw the user interface. So for iOS, I need to add a UIWebView to SDL’s UIWindow. I do that simply like this:
Code:
SDLwindow* sdlWindow = getWindow();
SDL_SysWMinfo info;
window* window;
SDL_VERSION(&info.version);
if (SDL_GetWindowWMInfo(sdlWindow, &info))
{
window = (info.info.uikit.window);
// Create the web view
UIWebView* webView = [[IOSWebView alloc] initWithFrame:window.bounds];
[webView setBackgroundColor: [UIColor clearColor]];
[webView setOpaque:NO];
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
// Add the web view to the current window
[window addSubview:webView];
// Load the user interface
NSURL *url = [NSURL fileURLWithPath:@"interface.html"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
That’s work great, I can see my interface over my SDL window but when I change the orientation of my device, only the SDL window rotate, the interface keep the same orientation all time.
I did a lot of researches and I found some solutions but they don’t work for me. Things I’ve tried was to change the webview’s autoresizingMask property like that:
Code:
webView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
But it doesn’t seem to work, the second to set the window’s autoresizesSubviews property to true:
Code:
window.autoresizesSubviews = YES;
Doesn’t work neither… And the last thing that I’ve tried was in Javascript:
Code:
[webView stringByEvaluatingJavaScriptFromString:@“var e = document.createEvent(‘Events’); e.initEvent(‘orientationchange’, true, false); document.dispatchEvent(e);”];
I’ve also seen a lot of messages that said to override shouldAutorotateToInterfaceOrientation method of the WebViewController, but I don’t have any controller for my webview. I tried to do something like that:
Code:
IOSWebViewController *iOSWebViewDelegate = [[IOSWebViewController alloc] init];
[webView setDelegate: iOSWebViewDelegate]; // Doesn’t work
webView.delegate = iOSWebViewDelegate; // Doesn’t work neither
But without any success… :’(
I’m not good at all with Objective-C, anybody to help me ?
Thanks in advance.