gpt4 book ai didi

iOS 快速指针

转载 作者:行者123 更新时间:2023-11-30 12:32:27 24 4
gpt4 key购买 nike

CGPoint startPoint1;
CGPoint startPoint2;
CGPoint startPoint3;
CGPoint startPoint4;

- (void)Method {
CGPoint* startPoint = NULL;

if (panGesture.view == ...) {
startPoint = &startPoint1;
} else if (panGesture.view == ...) {
startPoint = &startPoint2;
}

if (panGesture.state == UIGestureRecognizerStateBegan) {
*startPoint = [panGesture locationInView:...]
} else if (panGesture.state == UIGestureRecognizerStateChanged) {
CGPoint endPoint = [panGesture locationInView:...];
*startPoint = endPoint;
}
}

CGPoint* startPoint = NULL;
startPoint = &startPoint1;
*startPoint = endPoint;

这三行代码在Swift 3.0中是如何表达的或者我如何将上面的代码写入到swift中

最佳答案

在 swift 中,我会使用枚举和数组。我稍微简化了代码,但我想你会明白的:

var points = [CGPoint(), CGPoint()]
enum indexEnum:Int {
case startPoint = 0
case endPoint = 1
}

func method() {
var inx:indexEnum

if (1==1) {
inx = .startPoint
} else {
inx = .endPoint
}

if (2==2) {
points[inx.rawValue] = CGPoint(x:10,y:10)
} else {
points[inx.rawValue] = CGPoint(x:20,y:20)
}
}

关于iOS 快速指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43336203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com