ios new game project, rectangle displayed offscreen? - ios

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.

Related

How to show SwiftUI preview in landscape

.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)

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

How to resize SKScene in editor?

I've designed an SKScene for iPhone 4S in landscape (960x640)
I now want to use the same scene on iPhone 5, 6 etc
Is there any way to "easily" adapt this scene? I mean in a way similar to AutoLayout for Storyboards.
I don't want to have to copy this scene for each size and move everything again manually.
The Scale Mode is Aspect Fit, but that doesn't use the whole screen. Aspect Fill causes some sprites to be partially off-screen.

Get Auto-Layout to work with Notification Center width for Today Extension in iOS 8

For an iOS 8 Today Extension I am trying to position multiple square views in a way that they use the total width of the Notification Center.
Using Auto-Layout I got it to work as expected on the iPhone 5S and below. Everything works fine on these 4-inch and below devices because the Notification Center uses the whole screen width in both portrait and landscape mode.
However, the new iPhone 6(+) and all iPads do not use their whole screen width do display the Notification Center. This is what messes up my views. They still fill up the whole width of the NC, but they are not squares anymore but stretched vertically. I guess that Auto-Layout is being presented with a width of the whole screen width and does its calculations. In a second step however the NC then shrinks the views horizontally in order to fit them in the NC. This results in rectangles rather than squares.
How can I avoid this behavior? Seems to be a bug to me but any idea of a workaround?

Background color iOS 6 for application in landscape mode

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?

Resources