import Foundation import XCPlayground import UIKit import QuartzCore//Circle buttonclass timerbuttonGraphics: UIVIEw { overrIDe func drawRect(rect: CGRect) { let colorGreen = UIcolor(red: 0.310,green: 0.725,blue: 0.624,Alpha: 1.000) let colorRed = UIcolor(red: 241/255,green: 93/255,blue: 79/255,Alpha: 100) var bounds = self.bounds var center = CGPoint() center.x = bounds.origin.x + bounds.size.wIDth / 2 center.y = bounds.origin.y + bounds.size.height / 2 var radius = 61 var path:UIBezIErPath = UIBezIErPath() path.addArcWithCenter(center,radius: CGfloat(radius),startAngle: CGfloat(0.0),endAngle: CGfloat(float(M_PI) * 2.0),clockwise: true) path.strokeWithBlendMode(kCGBlendModenormal,Alpha: 100) path.linewidth = 5 colorGreen.setstroke() path.stroke() //@R_419_5552@ the animation here var anim = CABasicAnimation() anim.keyPath = "scale.x" anim.fromValue = 1 anim.tovalue = 100 anim.delegate = self self.layer.addAnimation(anim,forKey: nil) }}var test = timerbuttonGraphics(frame: CGRect(x: 0,y: 0,wIDth: 400,height: 400))test.setTranslatesautoresizingMaskIntoConstraints(true)XcpshowVIEw("Circle Animation",test)`解决方案的第一部分是启用“在完全模拟器中运行”选项.请参阅 this answer以获取详细步骤.
解决方案的第二部分是在容器视图中包含您的动画视图,例如:
let container = UIVIEw(frame: CGRect(x: 0,height: 400))XcpshowVIEw("Circle Animation",container)let test = timerbuttonGraphics(frame: CGRect(x: 198,wIDth: 4,height: 400))container.addSubvIEw(test)
解决方案的第三部分是纠正您的动画. keyPath应该是transform.scale.x而不是scale.x,你需要添加一个持续时间,例如:
anim.keyPath = "transform.scale.x"anim.duration = 5
然后,您应该能够在游乐场中查看动画.
总结以上是内存溢出为你收集整理的Swift游乐场中的CABasicAnimation全部内容,希望文章能够帮你解决Swift游乐场中的CABasicAnimation所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)