Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Hotshot10101 · May 14, 2013 at 09:19 PM · ioslandscapewebview

iOS WebView in Landscape

I am trying to integrate a WebView into my Unity project. I will also need to get call backs from the web pages where the javascript in the web page can make calls into Unity.

I have a great WebView plugin sample that I have adapted for my needs the works really well except for a single problem.

My app starts in Landscape and will always be in landscape. When I browse to the web page that we are using for our back end the page comes up just fine. I tap in the text field and the keyboard comes up. Everything is still great. I can hit the next and previous and still good.

The problem is when I dismiss the keyboard the web page width shrinks to the width it would be if the page were in portrait mode.

I want to keep this as lite weight as possible. I looked at uWebKit and Prime31. Neither of those allow for the web page javascript to call back into Unity like mine does, so I can't use those. Plus they are heavy and expensive. What I have is so very close and lite weight if I could just solve this problem I would be golden. I just don't know enough about Obj-c to solve it on my own.

There is more to this class than I am showing here. I am just showing the stuff related to init, changing to landscape and such along with the dealloc in case I am forgetting something there.

The only problem is when the keyboard goes away the width changes to portrait width (it is still oriented correctly however).

I will now show the code I am using:

 #import <UIKit/UIKit.h>
 
 extern UIViewController *UnityGetGLViewController();
 extern "C" void UnitySendMessage(const char *, const char *, const char *);
 extern void UnitySetAudioSessionActive(bool active);
 extern void UnityPause(bool pause);
 
 @interface WebViewPlugin : NSObject<UIWebViewDelegate>
 {
     UIWindow *overlayWindow;
     UIActivityIndicatorView *spinner;
     
     UIWebView *webView;
     NSString *gameObjectName;
     
     CGRect orientedFrame;
 }
 @end
 
 @implementation WebViewPlugin
 
 - (id)initWithGameObjectName:(const char *)gameObjectName_
 {
     self = [super init];
     
     CGRect bounds = [[UIScreen mainScreen] bounds];
     orientedFrame = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.height, bounds.size.width);
     
     overlayWindow = [[UIWindow alloc] initWithFrame:bounds];
     
     float angle = M_PI_2;
     CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
     [overlayWindow setTransform:transform];
     
     webView = [[UIWebView alloc] initWithFrame:orientedFrame];
     webView.delegate = self;
     webView.hidden = NO;
     webView.center = overlayWindow.center;
     
     [overlayWindow addSubview:webView];
     
     [overlayWindow makeKeyAndVisible];
     
     gameObjectName = [[NSString stringWithUTF8String:gameObjectName_] retain];
     
     return self;
 }
 
 - (void)dealloc
 {
     [webView removeFromSuperview];
     [webView release];
     [overlayWindow release];
     overlayWindow = nil;
     [gameObjectName release];
     [super dealloc];
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Hotshot10101 · May 22, 2013 at 08:00 PM

It turns out the problem was a totally different problem. It was the auto zooming that jQuery Mobile does in the WebView that iOS uses.

To fix this scaling issue all I had to do was modify the meta tag for the viewport as follows:

 <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1, maximum-scale=1" />

The important part is to have the initial-scale=1, minimum-scale=1 and maximum-scale=1 all match. At first I didn't have the initial-scale=1 and it still zoomed when I didn't want it to.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

AdMob iOS for Unity 4.1 2 Answers

How to use option setting Vibrate and Mute 1 Answer

entry point not found exception : TTS initialize 0 Answers

Execute native ios code in unity 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges