Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 反向CGRect-Swift_Ios_Swift_Cgrect - Fatal编程技术网

Ios 反向CGRect-Swift

Ios 反向CGRect-Swift,ios,swift,cgrect,Ios,Swift,Cgrect,如何反转我的origin.x?我的origin.x从右开始我想从左开始。例如,我的应用程序中x的这些起源从最右边开始: 1) 351.0 2) 304.0 3) 257.0 4) 210.0 5) 163.0 6) 116.0 7) 69.0 8) 22.0 我怎样才能逆转这些起源,从22.0开始到351.0结束 代码: var ansWithoutSpaces = String() ansWithoutSpaces = answersString.replacingOccurrences(of

如何反转我的
origin.x
?我的
origin.x
从右开始我想从左开始。例如,我的应用程序中x的这些起源从最右边开始:

1) 351.0

2) 304.0

3) 257.0

4) 210.0

5) 163.0

6) 116.0

7) 69.0

8) 22.0

我怎样才能逆转这些起源,从22.0开始到351.0结束

代码:

var ansWithoutSpaces = String()
ansWithoutSpaces = answersString.replacingOccurrences(of: " ", with: "")

var targetHeigt = CGFloat()
let viewWidth = self.view.frame.size.width  

if viewWidth == 320 {        
    targetHeigt = 2.5
} else {            
    targetHeigt = 5
}

let yAxis : Int = Int((self.view.frame.height) * 60%)     
let lenghtOfChar = ansWithoutSpaces as NSString
// char count
let width: Int = Int(view.frame.size.width) - 40
// frame width
var targetWidth: Int = (width - (lenghtOfChar.length - 1) * 5) / lenghtOfChar.length

if targetWidth > 50 {
    if viewWidth == 320 {
        targetWidth = 38 
    } else if viewWidth == 375 {
        targetWidth = 45
    } else {
        targetWidth = 50
    }
}

let totalWidth: Int = (targetWidth * lenghtOfChar.length) + ((lenghtOfChar.length - 1) * 5)

for x in 0..<ansWithoutSpaces.count {
    let xAxis: Int = (width / 2) - (totalWidth / 2) + (x * targetWidth) + (x * 5) + 20
    let targetLabel = UILabel(frame: CGRect(x: CGFloat(xAxis), y: CGFloat(yAxis), width: CGFloat(targetWidth), height: targetHeigt))

        ...    
}
var ansWithoutSpaces=String()
ansWithoutSpaces=answersString.replacingOccurrences(of:,with:)
var targetHeigt=CGFloat()
让viewWidth=self.view.frame.size.width
如果viewWidth==320{
targetHeigt=2.5
}否则{
targetHeigt=5
}
让yAxis:Int=Int((self.view.frame.height)*60%)
让lenghtOfChar=ansWithoutSpaces作为NSString
//焦数
let width:Int=Int(view.frame.size.width)-40
//帧宽
var targetWidth:Int=(宽度-(lenghtOfChar.length-1)*5)/lenghtOfChar.length
如果目标宽度>50{
如果viewWidth==320{
targetWidth=38
}如果viewWidth==375,则为else{
targetWidth=45
}否则{
targetWidth=50
}
}
让totalWidth:Int=(targetWidth*lenghtOfChar.length)+(lenghtOfChar.length-1)*5)
对于0中的x…@Nordeast解决了这个问题:

for x in (0..<ansWithoutSpaces.count).reversed() {
        ...    
}
对于x英寸(0..
对于跨步排列索引(from:ansWithoutSpaces.count-1,到:0,by:-1){
x=ansWithoutSpaces[arrayIndex]
}

更改用于
xAxis
的公式。这就是你想要的吗?问题是什么?尝试将原点插入数组中,然后可以使用array.reverse以相反的顺序获取它们。是的,我想反转
xAxis
@rmaddy我该如何做?你可以尝试反转x in(0.)的上一个for循环
。。