首页 > 解决方案 > Xcode:“GameView”类型的值没有成员“view”

问题描述

我尝试使用 Xcode 游乐场制作一些东西。当我尝试使用自动布局功能时,我收到一条错误消息,显示“GameView”类型的值没有成员“视图”

这是我的代码,还有更多,但我只添加了相关的部分。

import Foundation
import UIKit
import SpriteKit
public class GameView : UIView{
self.frame.size.width, height: self.frame.size.height))
    override public init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 0, width: 1500, height: 1000))

    }
    public override func addConstraints(_ constraints: [NSLayoutConstraint]) {
        self.view.addConstraints([
            NSLayoutConstraint(item: GameView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
            NSLayoutConstraint(item: GameView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
            NSLayoutConstraint(item: GameView, attribute: .centerX, relatedBy: .equal, toItem: self.view, attribute: .centerX, multiplier: 1.0, constant: 0),
            NSLayoutConstraint(item: GameView, attribute: .centerY, relatedBy: .equal, toItem: self.view, attribute: .centerY, multiplier: 1.0, constant: 0),
            ])
    }
}

提前致谢!

标签: iosswiftxcode

解决方案


好吧,它没有view属性,我想您只想使用self. 您可能从某种UIViewController.


推荐阅读