亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iPhone Core動畫-畫一個圓

iPhone Core動畫-畫一個圓

守著一只汪 2019-10-05 14:36:04
我希望創建一個動畫。我能解釋的最好方法是,如果您可以想象畫一個圓。它從頂部或12點開始,一直沿順時針方向繪制,直到在10秒鐘左右的時間內變成一個完整的圓圈。我來到的壁櫥是使用Core Animation(使用此處的示例代碼)繪制圍繞中心點旋轉的點。但是我對如何畫圈不知所措?任何建議都非常歡迎。非常感謝 :)
查看完整描述

3 回答

?
縹緲止盈

TA貢獻2041條經驗 獲得超4個贊

這是基于@David的答案的另一種解決方案。這種方法使您可以設置圓形動畫的方向,并提供更多的控制權。編輯:我已經寫了一篇關于如何使用Swift繪制圓的博客文章,我將嘗試與beta保持同步。檢查下面的代碼是否不適合您。


let radius = 100.0


// Create the circle layer

var circle = CAShapeLayer()


// Set the center of the circle to be the center of the view

let center = CGPointMake(CGRectGetMidX(self.frame) - radius, CGRectGetMidY(self.frame) - radius)


let fractionOfCircle = 3.0 / 4.0


let twoPi = 2.0 * Double(M_PI)

// The starting angle is given by the fraction of the circle that the point is at, divided by 2 * Pi and less

// We subtract M_PI_2 to rotate the circle 90 degrees to make it more intuitive (i.e. like a clock face with zero at the top, 1/4 at RHS, 1/2 at bottom, etc.)

let startAngle = Double(fractionOfCircle) / Double(twoPi) - Double(M_PI_2)

let endAngle = 0.0 - Double(M_PI_2)

let clockwise: Bool = true


// `clockwise` tells the circle whether to animate in a clockwise or anti clockwise direction

circle.path = UIBezierPath(arcCenter: center, radius: radius, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: clockwise).CGPath


// Configure the circle

circle.fillColor = UIColor.blackColor().CGColor

circle.strokeColor = UIColor.redColor().CGColor

circle.lineWidth = 5


// When it gets to the end of its animation, leave it at 0% stroke filled

circle.strokeEnd = 0.0


// Add the circle to the parent layer

self.layer.addSublayer(circle)


// Configure the animation

var drawAnimation = CABasicAnimation(keyPath: "strokeEnd")

drawAnimation.repeatCount = 1.0


// Animate from the full stroke being drawn to none of the stroke being drawn

drawAnimation.fromValue = NSNumber(double: fractionOfCircle)

drawAnimation.toValue = NSNumber(float: 0.0)


drawAnimation.duration = 30.0


drawAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)


// Add the animation to the circle

circle.addAnimation(drawAnimation, forKey: "drawCircleAnimation")


查看完整回答
反對 回復 2019-10-05
  • 3 回答
  • 0 關注
  • 605 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號