通过屏幕迅速移动一个像素(Move a pixel through screen with swif

2019-10-23 11:40发布

我感兴趣的是具有和其它目的(静态的,不一定是动态的)一个VC和除此之外,我想有一个像素 (一个或四个,取决于它是否能够看到人眼)周围的边界移动屏幕的(因此在边界)。

我附上什么,我需要一张照片:

所以,我需要的是“像素”移动indefinetely做一个正方形,我还需要知道它在哪里做的东西在我的代码(SWIFT)

Answer 1:

您可以使用一个解决方案的东西

斯威夫特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)

斯威夫特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值将屏幕的4个角落,你希望你UIView要移动的对象。



文章来源: Move a pixel through screen with swift