Ios 翻译苹果样品“;“复杂的多点触摸操作”;编码成Swift

Ios 翻译苹果样品“;“复杂的多点触摸操作”;编码成Swift,ios,objective-c,swift,cfdictionary,Ios,Objective C,Swift,Cfdictionary,描述我在“处理复杂的多点触控序列”一节中要实现的目标。不幸的是,它显示在Objective-C中。我可以将它的大部分翻译成Swift,但当涉及到几行时,比如使用CFDictionary的行时,我真的不知道发生了什么 如果有人能帮助我理解/翻译清单3-4和3-5,或者建议处理多点触控事件的其他方法,我将非常感激。我离开了我不确定的地方 以下是Obj-C(存储触摸初始位置): 以下是检索初始位置的步骤: - (void)touchesBegan:(NSSet *)touches withEvent:

描述我在“处理复杂的多点触控序列”一节中要实现的目标。不幸的是,它显示在Objective-C中。我可以将它的大部分翻译成Swift,但当涉及到几行时,比如使用
CFDictionary
的行时,我真的不知道发生了什么

如果有人能帮助我理解/翻译清单3-4和3-5,或者建议处理多点触控事件的其他方法,我将非常感激。我离开了我不确定的地方

以下是Obj-C(存储触摸初始位置):

以下是检索初始位置的步骤:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     [self cacheBeginPointForTouches:touches];
}

- (void)cacheBeginPointForTouches:(NSSet *)touches {
    if ([touches count] > 0) {
        for (UITouch *touch in touches) {
            CGPoint *point = (CGPoint *)CFDictionaryGetValue(touchBeginPoints, touch);
            if (point == NULL) {
                point = (CGPoint *)malloc(sizeof(CGPoint));
                CFDictionarySetValue(touchBeginPoints, touch, point);
            }
            *point = [touch locationInView:view.superview];
        }
    }
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     CGAffineTransform newTransform = [self incrementalTransformWithTouches:touches];
}

- (CGAffineTransform)incrementalTransformWithTouches:(NSSet *)touches {
     NSArray *sortedTouches = [[touches allObjects] sortedArrayUsingSelector:@selector(compareAddress:)];

     // Other code here
     CGAffineTransform transform = CGAffineTransformIdentity;

     UITouch *touch1 = [sortedTouches objectAtIndex:0];
     UITouch *touch2 = [sortedTouches objectAtIndex:1];

     CGPoint beginPoint1 = *(CGPoint *)CFDictionaryGetValue(touchBeginPoints, touch1);
     CGPoint currentPoint1 = [touch1 locationInView:view.superview];
     CGPoint beginPoint2 = *(CGPoint *)CFDictionaryGetValue(touchBeginPoints, touch2);
     CGPoint currentPoint2 = [touch2 locationInView:view.superview];


     // Compute the affine transform
     return transform;
}
以下是我所做的:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    cacheBeginPoint(touches: touches)
}

func cacheBeginPoint(touches: Set<UITouch>) {
    if touches.count > 0 {
        for touch: UITouch in touches {
            var point: CGPoint? = CFDictionaryGetValue(???)
            if point == nil {
                point = ???
                CFDictionarySetValue(???)
            }
            point = touch.location(in: view?.superview)
        }
    }
}
override func touchsbegind(touch:Set,带有事件:UIEvent?){
cacheBeginPoint(触摸:触摸)
}
func cacheBeginPoint(触摸:设置){
如果0.count>0{
对于触摸:UITouch in Touchs{
变量点:CGPoint?=CFDictionaryGetValue(?)
如果点==nil{
点=???
CFT值(???)
}
点=触摸位置(在:视图?.superview中)
}
}
}
以及:

override func touchesend(touch:Set,带有事件:UIEvent){
var newTransform:CGAffineTransform=增量转换(触摸:触摸)
}
func增量转换(接触:集合)->CGAffineTransform{
var-sortedTouches:NSArray=???
var transform=CGAffineTransform.identity
var touch1:UITouch?=分类触摸[0]
var touch2:UITouch?=分类触摸[1]
变量beginPoint1:=CFDictionaryGetValue(???)
var currentPoint1:=触摸1?位置(在:视图?超级视图中)
变量beginPoint2:=CFDictionaryGetValue(???)
var currentPoint2:=触摸2?位置(在:视图?超级视图中)
返回变换
}

是否需要使用Swift?为什么不按原样使用Obj-C代码呢?恐怕我不知道如何使用Obj-C。一旦该代码在Swift中,我将能够对其进行操作并将其集成到我的其余代码中。您可以在Swift项目中安全地使用Obj-C类。更多信息请点击此处:
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) {
    var newTransform: CGAffineTransform = incrementalTransform(touches: touches)
}

func incrementalTransform(touches: Set<UITouch>) -> CGAffineTransform {
    var sortedTouches: NSArray = ???
    var transform = CGAffineTransform.identity

    var touch1: UITouch? = sortedTouches[0]
    var touch2: UITouch? = sortedTouches[1]

    var beginPoint1: = CFDictionaryGetValue(???)
    var currentPoint1: = touch1?.location(in: view?.superview)
    var beginPoint2: = CFDictionaryGetValue(???)
    var currentPoint2: = touch2?.location(in: view?.superview)

    return transform
}