.previewLayout(.fixed(width: 480, height: 320)) has no effect in Xcode 13.4 and Xcode 14 beta 3
The preview is shown in portrait vs expected landscape
To make it clear here, you did not actually set your preview in landscape mode. Two solutions for your problem:
You actually requested the preview to be in a fixed size window, so to make this work, you need to choose Selectable in the canvas window to preview in a fixed sized window. I have drawn a red line around that part in the attached image. (code and image are below)
FContentView() //fixed size window
.previewLayout(.fixed(width: 480, height: 320))
If you want to actually preview in a landscape mode, use .previewInterfaceOrientation(.landscapeLeft) or right. You can choose either live / selectable. (code and image are below)
FContentView() //real landscape view
.previewInterfaceOrientation(.landscapeLeft)
Related
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!
I have a UIWebview and I load a URL into it. The URL is a streaming video.
When the video is displayed, the left side is cut off - approx 1/2 inch is not visible.
I have tried all different things in the storyboard editor having to do with ScalesPagesToFit being checked/unchecked and the View Mode Scale to Fill, Aspect Fit, Aspect Fill, etc. Nothing seems to make a difference.
I am on XCode 6.2 and the iPad I am testing on is 8.4. I am targeting 8.1 and above for this project.
EDIT: OK that got me looking on a different track. Maybe it is not available from within the storyboard, but by putting in this line of code in viewWillAppear it works:
[_thewebView setFrame:self.view.bounds];
I created a new game project using swift in xcode 6. I added a rectangle to the game scene like so,
let leftBoundRect = SKSpriteNode(color: UIColor.blackColor(), size: CGSize(width: self.size.width/2, height: self.size.height))
leftBoundRect.position = self.anchorpoint
self.addChild(leftBoundRect)
I also changed the display orientation from protrait to landscape by unchecking the portrait setting, so it displays in widescreen now.
So basically the rectangle is displayed, but it starts offscreen. In fact it takes up about a quarter of the screen instead of the half screen that I wanted. That makes me think that the scene's anchorpoint is offscreen and its not being entirely shown on the screen either?
Anyways I would like to display a black rectangle that takes up the left half of the screen.
I fixed this by changing the scaleMode to ResizeFill, by default it is AspectFill. Really I'm not entire sure about all these 4 different scaling modes but ResizeFill did it for me.
I have the following code in the viewWillAppear function:
CAGradientLayer *bgLayer = [BackgroundLayer yellowGradient];
[bgLayer setBounds:self.view.bounds];
[self.view.layer insertSublayer:bgLayer atIndex:0];
It works perfectly in portrait orientation. However, when the device goes into landscape mode, it produces a white (or default color) background down the side. I have seen other examples of WHY this occurs, but nothing on how to fix it.
What I’m seeing happening is the 1024 resolution on landscape (iPad) dropping to 1004, and I think it’s adjusting it to 0,20 on the x, y.
Has anyone else run into this issue and found how to fix it?
It’s because when you turn the screen sideways, your view, which has a certain background color, does not turn sideways. The view remains in portrait. So you have this portrait-oriented colored view that’s going from the new “top” of the iPad to way below off screen, and on the right side, the view isn’t wide enough to reach, so you just see the app’s default (white) background color.
You can:
apply a CGAffineTransformMakeRotation rotation to your self.view 90º, so that it now displays properly in your now-landscape application,
make your view big enough to cover the entire device, in both landscape and portrait,
make a view with the proper landscape dimensions, and add it when the iPad rotates, or
disable those allowed interface orientations in your Xcode main project file.
Link to CGAffineTransformRotation Demo Code on SO: How to use CGAffineTransformMakeRotation?
I have created simple windows based application. In my app delegate I have added a parentviewcontroller.view. In that parentview controller I am adding an image. Its position is given below.
In landscape: CGRectMake(0, 0, 1024, 54)
In portrait : CGRectMake(0, 0, 768, 54)
If I launch the app either in simulator/ipad, in landscape mode it shows perfectly. But when I launch the app in portrait mode, the top 20px of the UI and/or image is not being shown. But once I start changing the orientation it shows the image in correct position(in both landscape and portrait modes).
Please clarify me if I am doing anything wrong.
Thanks and Regards,
durai