animation - How to add imageView along the edge of PieChart in Swift -


i made animating piechart in swift. (at first filled circle showed, , next fades away.) want line image along edge of piechart image below, doesn't move along animating piechart. (i want add , move image red line of picture) sample image

how can solve it?

import uikit  class piegraph: uiview {      var _params:[dictionary<string,anyobject>]!     var _end_angle:cgfloat!     var rate:cgfloat = 100     var value:cgfloat = 0     var radians:double = 0      required init(coder adecoder: nscoder) {         fatalerror("init(coder:) has not been implemented")     }      init(frame: cgrect,params:[dictionary<string,anyobject>]) {         super.init(frame: frame)         _params = params;         self.backgroundcolor = uicolor.clear;         _end_angle = -cgfloat(double.pi * 0.5);     }       func update(link:anyobject){         let angle = cgfloat(double.pi*2.0 / 100.0);         _end_angle = _end_angle + angle          var percent:float!         radians = 0          dic : dictionary<string,anyobject> in _params {             percent = float(dic["value"] as! float)         }          if percent <= 10 {             //307°             radians = 5.3581608036         }else if percent <= 20 {             //285°             radians = 4.9741883682         }else if percent <= 30 {             //260°             radians = 4.5378560552         }else if percent <= 40 {             //238             radians = 4.1538836197         }else if percent <= 50 {             //216°             radians = 3.6 * double.pi / 3.0         }else if percent <= 60 {             //198             radians = 3.4557519189         }else if percent <= 70 {             //172             radians = 3.0717794835         }else if percent <= 80 {             //154°             radians = 2.6878070481         }else if percent <= 90 {             //130             radians = 2.2689280276         }else if percent <= 100 {             //115             radians = 0         }          if(_end_angle > cgfloat(double.pi * 1.5 - radians)) {             _end_angle = cgfloat(double.pi * 1.5)             //finish             link.invalidate()         } else {             self.setneedsdisplay()         }      }      func startanimating(){         _end_angle = -cgfloat(double.pi * 0.5);         let displaylink = cadisplaylink(target: self, selector: #selector(self.update))         displaylink.add(to: runloop.current, formode: runloopmode.commonmodes)     }       // override drawrect: if perform custom drawing.     // empty implementation adversely affects performance during animation.     override func draw(_ rect: cgrect) {         // drawing code          let context:cgcontext = uigraphicsgetcurrentcontext()!;         var x:cgfloat = rect.origin.x;         x += rect.size.width/2;         var y:cgfloat = rect.origin.y;         y += rect.size.height/2;         let max:cgfloat = 1.0;          dic : dictionary<string,anyobject> in _params {             value = cgfloat(dic["value"] as! float)         }          var start_angle:cgfloat =  cgfloat(double.pi * 1.5);         var end_angle:cgfloat    = -cgfloat(double.pi * 0.5);         let radius:cgfloat  = x - 10.0;          dic : dictionary<string,anyobject> in _params {             let value = cgfloat(dic["value"] as! float)             end_angle = start_angle - cgfloat(double.pi*2) * (value/max);              if(end_angle < _end_angle) {                 end_angle = _end_angle;             }              let color:uicolor = dic["color"] as! uicolor              context.move(to: cgpoint(x: x, y: y));             context.addarc(center: cgpoint(x: x, y: y), radius: radius, startangle: start_angle, endangle: end_angle, clockwise: true)             context.setfillcolor(color.cgcolor.components!);             context.closepath();             context.fillpath();             start_angle = end_angle;         }      }  } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -