How do I make the SwiftUI canvas preview horizontal - ios

I have tried to use .previewLayout(.fixed(width: 1334, height: 750)) syntax to make it look like Iphone8 screen horizontally(I don't know any other way,I remember on Xcode of previous version,I can choose device to be landscape left or landscape right or portrait for preview canvas), but it is not consistent with the actual simulator layout as the picture shows below.
but when it's Vertical, they both look the same.
How can I make them look the same when it is horizontal(landscape left or right)?
please help me, thanks a lot.
Different pattern here

I have figured out that why they look different,It's because that I did not know the difference between the concept of points and pixels. Besides, SwiftUI does not support landscape mode!

Related

Game is in landscape-only but view is in portrait?

I'm trying to draw a line from the bottom middle to the center of the screen. The values I was using for my two points seemed really odd so I knew something was off. I changed the aspect mode to aspectFit to see what was happening and lo and behold my view seemed to be in portrait even though my app specifies landscape. Does anyone know what is causing this? In the build settings I have only landscape checked.

How to make circles stay circles and resize on different screen sizes?

I really need help, I made an app I designed everything for iphone 7 I designed it with constraints and now I am having a problem because they don't look right on SE or 4s.
I am using circles made with IBDesignables(using cornerRadius to make circles). I want them when it resizes to stay circles because I tried couple of things and when it resizes its not a circle anymore.
Sorry for the long paragraph I just really need a tip !
How can I solve this problem
Here is how it looks on Iphone 7
Here is how it looks on Iphone SE
Here is how it looks on Iphone 4s
If you want to keep that all view stay circle for all device you must keep their height and width same.
You can easily do this thing with Autolayout set Aspect ratio of that view is 1 so their height and width remain same check screen shot

Icons overlap line items in landscape view

In a mobile app developed by a friend when you are in landscape mode on an iPhone there are icons that overlap text.
I wonder if this is a common problem and if it is obvious to anyone what possible factors could cause this?
See screenshots below:
Regular
Landscape
There has to be an issue in the project with constraints. The text and the icons are not constrained to themselves so when the screen width changes their position changes as well. It looks like the icons are misplaced in the landscape view so I would start looking for the solution in that direction.
This is quite common and thankfully easy to fix mistake. New developers are working with fixed screen sizes and forget that there are multiple sizes to consider. Working with constraints will come along with experience so don't worry.

Landscape only on XCode 6

Hi so I've been playing around with XCode and can't seem to figure out how to make an application landscape only. Wondering if there is a simple/storyboard solution.
I've tried checking the landscape left and landscape right and unchecking the portrait on the general page under "device orientation".
However this strangely just displays the w Compact h Regular set up on my storyboard horizontally (as opposed to showing the W Any h Compact set up). I mean technically I can work around this, but it seems annoying/inefficient to rotate my head 90 degrees while working on the portrait settings.
If there is only solution in code, I would appreciate it in swift!
EDIT: Hmmm, after some testing it seems as if the phone I'm testing on only shows the rotated version of the portrait settings. It's an iPhone 4 and maybe outdated for handling 2 seperate set ups for portrait and landscape.
Thanks!
Just for anyone with this problem in the future, here's the problem:
The storyboard editor by default will display the editor as any by any, as it should. Size classes should ONLY be used when you need to change something specifically for one kind of size class (in other words, things that will be different on different devices. You should still edit everything in the any x any orientation, and regardless of if it's landscape only because size classes will still change from device to device for landscape orientation.
It's an iPhone 4 and maybe outdated for handling 2 seperate set ups for portrait and landscape
That could be it. Size Classes were invented in iOS 8. So on a system earlier than iOS 8, they are not supported, and your results will be, shall we say, unpredictable.

UIViewController Size doesn´t work

Hi im currently developing an Universal app for iPhone, iPod and iPad. I have all view controllers in both storyboards set to Inferred. It works fine on iPhone Retina and on all iPads but when you put it in landscape mode it gets all messed upp and on the iphone 3,5 inch simulator the bottom gets cut off. How can i fix this? Do i have do create seperate view controllers for landscape mode and iphone 3,5? And the write some code that recognizes if its in landscape mode and iphone 4? I thought this worked automatically. Or have i done something wrong?
There is no quick fix/answer to your question.
Since the screen size is different while using horizontal and vertical orientations - it is simply not the same canvas and thus you will need to do some manual work to set it right.
Strategy 1.
Assuming your layout is simple - there are not too many elements and all elements can theoretically fit both horizontal and vertical screen size:
You should use auto layout from the Interface builder - Look at an excellent video from WWDC
https://developer.apple.com/wwdc/videos/
(video 406 - Taking Control of Auto Layout in Xcode 5)
In few words - you set spacers to your elements, aligning them to the end of your view (dynamically), therefore you can make your element shrink and move automatically respecting the current screen orientation.
Strategy 2.
Assuming your UI is complex and will not fit both orientations:
have a different xib file for horizontal and vertical views, this can take some time, but it is a solid solution that always looks good.
You simply need to track changes in orientation and load the appropriate xib.
Your problem will only be solved if you use Autolayouting and for that you need to go through some tutorials
Ray's Tutorial
Another Very well explained tutorial
Going through the above articles will definately help you in solving your problem

Resources