快速在屏幕上移动一个像素 [英] Move a pixel through screen with swift

查看:25
本文介绍了快速在屏幕上移动一个像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm interested in having a VC with objects and others (static, not necessarily dynamic) and apart from that, I want to have a pixel (one or four, depending if it can be seen for the human eye) moving around the borders of the screen (so in the bounds).

我附上了一张我需要的照片:

I attach a photo of what I need:

所以我需要像素"无限地移动做一个正方形,我还需要知道在我的代码中做某事的位置(快速)

So I need that the "pixel" move indefinetely doing a square and I also need to know where it is to do something in my code (in swift)

推荐答案

您可以使用解决方案来

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)

斯威夫特 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 个角.

The CGPoint values would the 4 corners of your screen where you want your UIView object to move.

这篇关于快速在屏幕上移动一个像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆