What is the best manner to create a layout per device?
Right now i am working with constraints but i cant get it right.
The width/height from my so called gameView is to small to fit the puzzle pieces.
This is the right width/height to fit the puzzle pieces for the iPhone 11
And this is the view on the iPhone 8
Pieces
My solution to get it all fit is to set the frame sizes per device
But i don't know if it is the right solution.. I can imagine that there are better solutions..
if UIDevice.current.deviceCategory() == .iPhone8 {
turnOffConstraints()
topView.frame = CGRect(x: 0, y: 0, width: topView.frame.width, height: 70)
categoryLabel.frame = CGRect(x: 88, y: 23, width: 199, height: 35)
totalMovesSV.frame = CGRect(x: 308, y: 78, width: 50.5, height: 44)
timerSV.frame = CGRect(x: 20, y: 78, width: 50.5, height: 44)
gameView.frame = CGRect(x: 20, y: 130, width: 335, height: 335)
hintSV.frame = CGRect(x: 161, y: 473, width: 52, height: 80.5)
backButtonSV.frame = CGRect(x: 52, y: 8, width: 52, height: 80.5)
showOriginalButtonSV.frame = CGRect(x: 161, y: 8, width: 52, height: 80.5)
levelsButtonSV.frame = CGRect(x: 275, y: 8, width: 52, height: 80.5)
bottomView.frame = CGRect(x: 0, y: 567, width: topView.frame.width, height: 100)
}
The App is working and everything fits like i wanted but now my debugger is full with this kind of messages:
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2020-06-12 15:24:55.282095+0200 Sliding Game[35445:2539475] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
I am curious what the right approach is..
You give constant values to your all components.Its maybe looking good some devices but It doesnt mean looks fine in all.Lets say yout giving 160px height for a component. It will look ok on iPhone XsMax (height is 896px) almost One fifth of the screen. But when you run in iPhone 5, SE..(height is 568px) almost one fourth of the screen.
Giving constant value can occur intertwine of components. This is what Debug screen want to say.
You can estimate components to the screen or make anchor each other for avoiding it
Related
I'm working on Swift 5 with Xcode 11.7 in a project. In here, I have a button and draw a rectangle around it. Everything is fine until I run it in iPhone 11 (11 pro, 11 pro max) simulator. Even I have set x,y of rectangle as same as the button's but they are skewed, other simulator didn't have this situation.
How can I fix this problem. Many thanks.
Question to me if it is not clear enough for you.
Here is my code to make a rectangle and make it around the button.
let rect = CGRect(x: btnSignIn2.frame.origin.x - 10, y: btnSignIn2.frame.origin.y + btnSignIn2.layer.bounds.height + 10, width: btnSignIn2.layer.bounds.width + 20, height: btnSignIn2.layer.bounds.height + 20)
let spotlight1 = AwesomeSpotlight(withRect: rect,
shape: .roundRectangle,
text: "message_please_login".localized(),
labelPosition: CGRect(x: 0, y: rect.maxY - btnSignIn2.layer.bounds.height + 25, width: UIScreen.main.bounds.width, height: 100),
isAllowPassTouchesThroughSpotlight: true)
The screenshot I put down here is the problem I have. The left side is iPhone11, and the other side is one of other simulator.
I want change normal line to bezier curve with this:
var grayBezierLine = new Konva.Line({
points: [50, 50, 100, 100, 150, 50, 200, 100, 250, 50, 300, 100, 350, 50],
stroke: 'gray',
strokeWidth: 15,
lineCap: 'round',
lineJoin: 'round',
bezier: true,
});
but the display is weird, after check the sourcecode, found this:
if (bezier) {
// no tension but bezier
n = 2;
while (n < length) {
context.bezierCurveTo(
points[n++],
points[n++],
points[n++],
points[n++],
points[n++],
points[n++]
);
}
}
At first I thought except the first(50, 50) point and last point(350, 50), all intermediate points are control points, but it's not, every three points forms a curve.
this is a reproduce demo.
My question is this a deliberate design or a bug?
I'm trying to set my buttons and images to be in a specific spot on all Iphone screen sizes. Normally I would use CGPoint(width: self.frame.width, height: self.frame.height) , but in buttons you use .Frame which is different, and I write .frame = CGRect(x: self.frame.width / 7.7, y: self.frame.height / 2.6, width: self.frame.width / 10, height: self.frame.height / 12)
, but it works on one screen for say iphone 6, but then on a iphone 5 it is in a different spot... any suggestions??
Following the example as below URL.
https://gist.github.com/nyg/b8cd742250826cb1471f
It is a great example for me if can set bottom space more perfect.
After a lot of test and search with any possible,
I find this theme (
Is there any way to generate PDF file from a XML/HTML template in iOs)
and revise some codes as below:
//let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8); // A4, 72 dpi
let page = CGRect(x: 0, y: 0, width: 575.2, height: 821.8); // A4, 72 dpi
..
..
..
//UIGraphicsBeginPDFContextToData(pdfData, CGRectZero, nil);
UIGraphicsBeginPDFContextToData(pdfData, CGRect(x: 0, y: 0, width: 595.2, height: 841.8) , nil);
I have a UIView whose dimensions are (x: 16, y: 360, w: 369, h: 81) and I want to hide it with a UIAction by just sending it out of the screen. So I did UIView.animateWithDuration(0.2, animations: {self.View.frame = CGRectMake(x: -410, y: 360, 369, 81)}), the ideal animation would be to have it slide out along the y-axis, however what I am getting now is the view going down and left (instead of just left). I'm kinda confused since I kept the 'y' the same in animation.
You are moving the view of the view controller NOT the view that you want to move (note self.view ...):
self.View.frame = CGRectMake(x: -410, y: 360, 369, 81)
I think I found the problem, because I embedded my view in a navigation controller, the header is probably screwing with my coordinates, so I used frame.origin.x and frame.origin.y instead.