Ios SKShapeNode子类框架元素引用的是UIView,而不是SKNode

Ios SKShapeNode子类框架元素引用的是UIView,而不是SKNode,ios,swift,swift2,skshapenode,Ios,Swift,Swift2,Skshapenode,生成以下异常: 运算符“-”的用法不明确 以下是line和other类的对象类型声明: let dx = line.frame.midX - other.frame.midX 我注意到当我跳转到定义时(⌘ + 单击)在Xcode中,frame对象将我带到UIView中的frame属性,而不是SKNode 我的子类划分不正确吗?如何消除运算符异常错误的模糊用法?问题的出现是因为您在创建这些对象的类中既没有导入UIKit也没有导入SpriteKit 例如,如果您有,比如,GameViewContr

生成以下异常:

运算符“-”的用法不明确

以下是line和other类的对象类型声明:

let dx = line.frame.midX - other.frame.midX
我注意到当我跳转到定义时(⌘ + 单击)在Xcode中,
frame
对象将我带到
UIView
中的
frame
属性,而不是
SKNode


我的子类划分不正确吗?如何消除运算符异常错误的模糊用法?

问题的出现是因为您在创建这些对象的类中既没有导入
UIKit
也没有导入
SpriteKit

例如,如果您有,比如,
GameViewController
类:

import Foundation
import SpriteKit

class Line: SKShapeNode {
    var plane:Plane!

    init(rect: CGRect, plane: Plane) {
        super.init()
        self.path =  CGPathCreateWithRect(rect, nil)
        self.plane = plane
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
请确保导入上述任一框架:


other
引用的类是什么?@pricingo other也是一种类型的Line classI无法解释
Line
other
是否都是
Line
对象,甚至是
Line
UIView
对象。当编译器无法解析
-
运算符两侧的类型时,将抛出
不明确的
错误消息。确保两者都是
CGFloat
。这将是解决这个问题的起点。@Pricingo,是的!这是我的问题。无法解析
line.frame
other.frame
对象中的midX属性。向后操作时,两个帧对象的行为就像它们是
UIView
对象一样,这解释了它们为什么没有
midX
属性。但是为什么框架对象认为它们是
UIView
对象,而不是
SKNode
objectsThanks!那是我的问题。实际上,我是在一个实用程序/助手类中进行这些计算的,我忘了导入
SpriteKit
class GameViewController : UIViewController
import UIKit
//or
import SpriteKit

class GameViewController : UIViewController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        let line = Line(rect:....) //specify rect 
        let other = Line(rect:....) //specify rect

        let dx = line.frame.midX - other.frame.midX
    }

}