使用 swift 在屏幕上移动一个像素
Move a pixel through screen with swift
我对 VC 对象和其他对象(静态的,不一定是动态的)感兴趣,除此之外,我想要 pixel(一个或四个,取决于它是否可以被人眼看到)在屏幕的边界周围移动(所以在边界内)。
我附上我需要的照片:
所以我需要 "pixel" 无限移动做一个正方形,我还需要知道在我的代码中做某事的位置(在 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)
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 个角。
我对 VC 对象和其他对象(静态的,不一定是动态的)感兴趣,除此之外,我想要 pixel(一个或四个,取决于它是否可以被人眼看到)在屏幕的边界周围移动(所以在边界内)。
我附上我需要的照片:
所以我需要 "pixel" 无限移动做一个正方形,我还需要知道在我的代码中做某事的位置(在 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)
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 个角。