ios - Move view in direction of specific angle -


i have angle calculating based on positioning of view centre of screen. need way move view it's current position, off screen in direction of angle.

i'm sure there simple way of calculating new x , y value, haven't been able figure out maths. want using animation, can figure out myself once have coordinates.

anyone have suggestions?

if have angle can calculate new coordinates getting sine , cosine values. can try out following code

let pathlength = 50 double // total distance view should move let pifactor = m_pi / 180 let angle = 90 double // direction in need move let xcoord = outview.frame.origin.x +  cgfloat(pathlength * sin(pifactor*angle)) //outview name of view want animate let ycoord = outview.frame.origin.y +  cgfloat(pathlength * cos(pifactor*angle)) uiview.animatewithduration(1, delay: 0, options: uiviewanimationoptions.curveeaseinout, animations: { () -> void in     self.outview.frame = cgrectmake(xcoord, ycoord, self.outview.frame.size.width, self.outview.frame.size.height)         }, completion: { (bool) -> void in }) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -