寻找一种干净的解决方案来以编程方式布置 UI 并使其在每台设备上看起来都正确。我试过扩展 CGFloat 以根据设备缩放数字
extension CGFloat {
func scale() {
// Modifies self by multiplies by the ratio between the initial screen size and the desired screen size
}
}
// usage
view.widthAnchor.constraint(equalToConstant: 20.scale())
Run Code Online (Sandbox Code Playgroud)
我还尝试为 iPhone 和 iPad 创建两组不同的约束并根据运行应用程序的设备激活它们,但这似乎不必要地冗长。
我如何布局我的 UI 以便它可以在所有设备上运行而没有hacky 解决方法。我应该避免某些类型的限制吗?(例如,不是设置宽度/高度常量,而是将它们设置为屏幕(或其他视图)宽度/高度的倍数?)
编辑:我不想过度解释我自己的情况,所以让我重新提出这个问题。在为 iPhone 和 iPad 设计的应用程序中设置约束的最佳实践有哪些?只检查设备是否是 iPad,如果是,只对 iPad 进行限制,如果不是,只对 iPhone 进行限制,这是不好的做法。
我正在编写一个程序,它接受4个数字作为输入,然后尝试查看加法减法除法和四个数字相乘的组合是否可以使它们等于24.我的方法是为四个数字的每个可能组合创建一个方法数字和四个操作数,有点冗长.以下是2种方法的示例.
public static boolean add(int a, int b, int c, int d){
boolean adBool;
adBool = a + b + c + d == 24;
return adBool;
}
public static boolean sub1(int a, int b, int c, int d){
boolean subBool1;
subBool1 = a - b - c - d == 24;
return subBool1;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的Main中我为每个方法创建一个while循环,如果方法返回true,将打印它停止的方法,是解决方案.这是一个例子.
while (add(num1, num2, num3, num4)){
System.out.println("Your solution is " + num1 + " + " + num2 + " + " + num3 + …Run Code Online (Sandbox Code Playgroud) 我以前从未见过这种语法.
#define SNS(s) (s),(sizeof(s)-1)
Run Code Online (Sandbox Code Playgroud)
我正在读这个的方式就是这样SNS(s) = sizeof(s)-1.逗号在做什么?有必要吗?
int ft_display_fatal(const char *err, unsigned len, int fd, int rcode)
{
UNUSED(write(fd, err, len));
return (rcode);
}
Run Code Online (Sandbox Code Playgroud)
主要
return (ft_display_fatal(SNS("File name missing.\n"), 2, 1));
Run Code Online (Sandbox Code Playgroud) public static int[] sortArr(int[] a){
int temp;
for(int i = 0; i < a.length; i++){
temp = a[i];
a[i] = a[findMin(a, i)];
a[findMin(a, i)] = temp;
}
return a;
}
public static int findMin(int[] a, int start){
int min = a[start];
int minIndex= start;
for(int i = start; i < a.length; i++){
if(a[i] < min){
min = a[i];
minIndex = i;
}
}
return minIndex;
}
Run Code Online (Sandbox Code Playgroud)
sortArr方法只返回它给出的数组,我看不出原因.我已经在纸上做了它,它应该工作.任何人都能看到问题吗?
在开始学习 go 之前,我与Cand一起工作C++了一段时间,我很好奇为什么*intand[]int在 golang 中被视为不同的类型。是否将其视为数组取决于您,但它们都应该是指向内存中某个位置的指针,指示 int 类型列表的开头。该列表很可能是一号,但我的观点是,为什么在 go 中它们是同一件事[]int,而*int不是同一件事?