Ekranda her saniye yeni bir animasyonlu çizgi oluşturmaya çalışıyorum. Her saniyede yeni bir çizgi alıyorum, ancak eski olanı geçersiz kılıyor. Nedenini bilmiyorum ama muhtemelen aptal olduğum bir şey. animasyonlar birbirini geçersiz temelde ben animasyon zamanlama ile yaşıyorum bir sorun İşteDöngüleri Aşan Animasyonlar İçin
oluyor:
func repeatThis() {
var runningPath = UIBezierPath()
for x in 0...10 {
delay(Double(x)/10) {
let topLineStartPath = UIBezierPath(rect: CGRect(x: 0, y: x * 10, width: 1, height: 10))
let topLineEndPath = UIBezierPath(rect: CGRect(x: 0, y: x * 10, width: Int(self.bounds.width), height: 10))
let fullStartPath = runningPath.copy() as! UIBezierPath
fullStartPath.appendPath(topLineStartPath)
let fullEndPath = runningPath.copy() as! UIBezierPath
fullEndPath.appendPath(topLineEndPath)
let expAnimation: CABasicAnimation = CABasicAnimation(keyPath: "path")
expAnimation.fromValue = fullStartPath.CGPath
expAnimation.toValue = fullEndPath.CGPath
expAnimation.duration = self.animationTime
expAnimation.fillMode = kCAFillModeForwards
expAnimation.removedOnCompletion = false
self.addAnimation(expAnimation, forKey: nil)
print(x)
runningPath = fullEndPath
}
}
}
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
yardım
func repeatThis() {
for x in 1...10 {
let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), Int64(x) * Int64(NSEC_PER_SEC))
dispatch_after(time, dispatch_get_main_queue()) {
var topLinePatha: UIBezierPath {
return UIBezierPath(rect: CGRect(x: 0, y: 0 + (x * 10), width: 1, height: 10))
}
var topLinePathb: UIBezierPath {
return UIBezierPath(rect: CGRect(x: 0, y: 0 + (x * 10), width: Int(UIScreen.mainScreen().bounds.width), height: 10))
}
let expAnimation: CABasicAnimation = CABasicAnimation(keyPath: "path")
expAnimation.fromValue = topLinePatha.CGPath
expAnimation.toValue = topLinePathb.CGPath
expAnimation.duration = self.animationTime
expAnimation.fillMode = kCAFillModeForwards
expAnimation.removedOnCompletion = false
self.addAnimation(expAnimation, forKey: nil)
print(x)
}
}
}
Teşekkür
Düzenleme 1: İşte benim kod
Bu kodda 'self' nedir? Birden fazla satırın görünmesini istiyorsanız, bu nesneden daha fazlasını yapmak zorunda kalacaksınız. –
@KurtRevis Yani, böyle bir şey yapmanın daha kolay bir yolu var mı? –
@KurtRevis de kendini 'CAShapeLayer' –