gpt4 book ai didi

ios - Objective-C 属性和指向 Swift 的指针

转载 作者:行者123 更新时间:2023-11-28 12:33:41 25 4
gpt4 key购买 nike

我刚开始学习 Swift,我一直在查阅 Apple 的开发指南,但处理属性和指针时的一些语法让我失望。 Apple 解释说属性只使用点语法,甚至 API 似乎也反射(reflect)了这一点,但它并没有达到我想要的效果。这是我一直在做的具体工作。我也在为实例初始化而苦苦挣扎。 我已经正确地创建了一个桥接头任何指导将不胜感激。谢谢!

这是我试图在 swift 中模拟的代码。

@property (nonatomic) SFWaterNode *waterSurface;
@property (nonatomic) NSTimeInterval lastUpdateTime;
@end

@implementation GameScene

- (void)didMoveToView:(SKView *)view {
self.backgroundColor = [SKColor blackColor];

CGPoint startPoint = CGPointMake(-1, self.size.height/2);
CGPoint endPoint = CGPointMake(self.size.width, self.size.height/2);

self.waterSurface = [SFWaterNode nodeWithStartPoint:startPoint endPoint:endPoint depth:self.size.height/2 color:[SKColor blueColor]];
[self addChild:self.waterSurface];

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];

[self.waterSurface splash:location speed:-50];
}

- (void)update:(CFTimeInterval)currentTime {
[self.waterSurface update:currentTime];
}

@end

最佳答案

试试下面的代码:

public var waterSurface:SFWaterNode?
var lastUpdateTime:NSTimeInterval

func didMoveToView(view:SKView) {

self.backgroundColor = .black

let startPoint:CGPoint = CGPoint.init(x: -1, y: self.size.height/2)
let endPoint:CGPoint = CGPoint(x: -1, y: self.size.height/2)

self.waterSurface = SFWaterNode.nodeWithStartPoint(startPoint, endPoint:endPoint, depth:self.size.height/2, color:.blue)

self.addChild(self.waterSurface)

}

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

let touch:UITouch = touches.anyObject()
let location:CGPoint = touch.location(inNode: self)
self.waterSurface.splash(location, speed:-50)

}

func update(curentTime:CFTimeInterval) {

self.waterSurface.update(currentTime)
}

关于ios - Objective-C 属性和指向 Swift 的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41455120/

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