I am relatively new to Xamarin ios and am creating an application that
will work in both Landscape and Portrait for both iPhone and iPad.
I have been able to implement both Landscape and portrait on iPhone pretty fine by using a rotation callback method that will invoke a different view with the same layout but adjusted dimensions for the landscape version and on the landscape version I have the same to go back to portrait. This works okay but has some lag at times.
I'm not very sure about what is the right way to present two different UIs for different orientations. If anyone has any suggestions please let me know.
Now I have a list that holds values for Height and Width of the current device and I will devise this by the current device density like so:
maindisplayinfo.height / maindisplayinfo.density
and this gives me the current display dimensions I need. I use this to place my objects relative to a screen portion such as:
CGRect(0, Height * 0.30, Image.Bounds.Width, Image.Bounds.Height)
On rotation on Ipad, the display goes funny even though I have set dimensions correctly and my rotation callback triggers the different views. Not sure what is going on here.
But is there a certain way to do this sort of thing with iPad and iPhone?
Related
I'm trying to build a unity project for standalone and the game is in portrait configuration. Everything works fine when I test it in the editor, but when I build it, everything UI related is messed up and by that I mean it tries to fit to the screen's aspect ratio causing many buttons and UI elements to be off-screen despite even manually trying to change the screen size by doing Screen.SetResolution(1080, 1920, false); and stopping the game from entering full-screen mode in the build settings so that it would become a portrait aspect ratio but nothing is working. The game itself is working fine which is not a part of UI or any canvas obviously. Any help would be much appreciated!
UI scaling is tricky particularly is you have different aspect ratios, and also if you have different resolutions (although they are different). The most important things from my experience are making sure you've anchored things as reasonably as you can, used layout groups for dynamic content (dropdowns, instantiated elements, etc.) and used the CanvasScaler component on your canvas.
The Canvas Scaler component can be found on your canvas object in the scene, and is the first place to start when dealing with variable screen sizes. . This mode is the best for variable screen sizes, you can set this up to be your preferred screen size and then make your UI fit that size, then automatically scale based on your ideal size.
It's hard to say what is the best way to anchor your UI elements generally speaking, but if you don't want them centred on the middle of the screen it likely isn't the default. I often find anchoring the sides of an area, or corners, is best.
Finally, depending on your platform and handled screen orientations, you can also set device orientation preferences in Player Preferences. . Exactly what you set may depend on your project, but can be an important step in making sure your UI scales correctly for you targets.
I couldn't find an option to send a picture to better explain what's happening. Here's a Unity Link that has the photos to explain the issue.
I've tried Camera.main.orthographicsize = 4.0f, a solid number to stay on but the Orthographic Size of the camera keeps changing it's size after resizing the window when I'm in free aspect Unity editor mode and even when I export the Unity game with 1920x1080(16:9) resolution. I want it to stay the same size when resizing the window so that the game can always fit inside the screen in any resolution when resizing the window. The default blue background of the camera displays when I stretch the window's width far enough which I don't want to happen.
This Youtube video has the results I'm looking for but the code unfortunately is not working on Unity 2019. The code provided from this video does entirely different things for me and doesn't solve my issue.
From what I understood is that the screen has to has a fixed resolution.
This link will demonstrate the solution. https://docs.unity3d.com/Manual/GameView.html
It does that by changing the
Game View Aspect from free to a fixed resolution.
Unless this is not what you are looking for then I sugest another solution:
Make a black background image that fits the screen size.
Then change the scale of the objects in the scene relative to the camera.
This link will make the scaling solution, Make object visual size constant despite the distance
I have a problem with adjusting splashscreen in Xamarin Forms iOS project.
I'd like to change splashscreen static image depending on screen orientation.
In Android I simply, created drawable-land folder, put there image for landscape orientation and it's working.
In iOS project there is whole designer for purpose of creating launchscreens, but I can't find anything that will do the job. When I adjust image for Iphone, change orientation in designer I can't simply put there different image because it's shared across all screens in designer.
One important remark - I found some sources on how to achive that, but for native XCode designer, I need an answer for Visual Studio or VS for Mac.
Thanks in advance
Here whatever you apply, will be applied to landscape and portrait universally.
You can have different images, one for portrait 'splash_portrait.png' and one for landscape 'splash_landscape.png' in Assets.
You can then choose which image to display for landscape and which for portrait using Edit Traits button on the bottom right corner in your screenshot.
Landscape uses Any or Compact Height size class, so you would be selecting Compact Height checkbox and whichever change you apply, will be applied for this size class (landscape).
Please get more details on this, here & here
Practically, I haven't tried as while giving answer, I am away from computer. But I hope this will help.
https://www.youtube.com/watch?time_continue=1&v=y3lspdPxc6o,
Refer this tutorial video by Kym Phillpotts - Xamarin University Lightning Lecture.
On the widget properties, you have an option for the full-size splash.
I am using unity for develope to my android phone. I am trying to develope a 2D game. When I put new image(sprite) in my game i can see it fully in unity but when I uploaded the game to my phone, parts of the image are missing from the sides. How can I fit the images sizes on all phones?
I saw the answer for this question but for eclipes java and not unity C#.
In Unity 4.6 version, you can make you UI size adaptive:
Select the canvas where your UI resides
In the inspector, add a component called Canvas Scaler (in 4.6 beta, this is called Reference Resolution component)
Set the reference resolution to the native (or original size) of your sprite/background image
Make sure you choose the right "Screen Match Mode" if the phone's resolution is different.
That is it.
Now no matter how you resize the game view, your sprite can make best fit with it: either fit with the width or height, depending on the phone orientations and aspect ratios. In either case, however, you are guaranteed to see full image, rather than portion of it in your case. See the gif below:
Screen.width and Screen.height are the only unity specific methods you need.
Pass in height, width, and position information to your objects based on your screen size.
The harder part learning the gui.
If you need more help with syntax, take a look at unit's gui documentation and tutorials.
Use Screen.width and Screen.height to get the screen size of current device, then check your target phones screen aspect ratio:
For Window Phone, it's 5:3 and 16:9
iPhone: iPhone 3, 4 is 3:2, iPhone 5, 6, 6+ is 16:9
Android phone has many types.
After you get the that, make sure your sprites are designed in exact ratio for your target phones, and it'll be matched with screen.
I'm using Mono Touch to develop a landscape-only iPad application but the simulator doesn't seem to rotate any of the views (or the main window for that matter) to landscape.
I've set the SDK version and Minimum OS version to 4.2.
I have also set the Supported Orientations to Landscape.
Furthermore, I've created a Navigation Controller which overrides the ShouldAutorotateToInterfaceOrientation and sets it to return true. I then added it using window.AddSubview(navigationController.View) but that didn't help either.
I'm using the Rotate Left/Right methods (under Hardware) in the simulator but the whole app rotates with the window and the app stays in Portrait mode. Even the status bar (carrier, time, battery) go off to the right instead of moving up to the top of the screen.
Help?! Anyone?!
Have you set the UIInterfaceOrientation key to landscape as well?
Also, in shouldAutorotateToInterfaceOrientation you'll want to only return true if the new orientation matches the orientation you want.