gpt4 book ai didi

swift - 快速在屏幕上移动一个像素

转载 作者:搜寻专家 更新时间:2023-11-01 07:34:10 24 4
gpt4 key购买 nike

我对拥有包含对象和其他对象(静态的,不一定是动态的)的 VC 很感兴趣,除此之外,我想要一个像素(一个或四个,取决于它是否可以人眼所见)在屏幕边界周围移动(因此在边界内)。

我附上我需要的照片:

Mockup of what I need

所以我需要“像素”无限移动做一个正方形,我还需要知道在我的代码中它在哪里做某事(快速)

最佳答案

你可以使用一些解决方案来

swift 2

UIView.animateKeyframesWithDuration(4, delay: 0.0, options: UIViewKeyframeAnimationOptions.Repeat, animations: { () -> Void in

UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPointMake(0, 100)
})
UIView.addKeyframeWithRelativeStartTime(1/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPointMake(100, 100)
})
UIView.addKeyframeWithRelativeStartTime(2/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPointMake(100, 0)
})

UIView.addKeyframeWithRelativeStartTime(3/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPointMake(0, 0)
})

}, completion: nil)

swift 3、4、5

UIView.animateKeyframes(withDuration: 4, delay: 0.0, options: UIView.KeyframeAnimationOptions.repeat, animations: { () -> Void in

UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPoint(x: 0, y: 100)
})
UIView.addKeyframe(withRelativeStartTime: 1/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPoint(x: 100, y: 100)
})
UIView.addKeyframe(withRelativeStartTime: 2/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPoint(x: 100, y: 0)
})

UIView.addKeyframe(withRelativeStartTime: 3/4, relativeDuration: 1/4, animations: { () -> Void in
self.aView.center = CGPoint(x: 0, y: 0)
})

}, completion: nil)

CGPoint 值是您希望 UIView 对象移动的屏幕的 4 个角。

关于swift - 快速在屏幕上移动一个像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010360/

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