ios - Rotating a UIView around a center point without rotating the view itself -
i rotate uiview around center point without rotating uiview itself. more cars of ferris wheel (always staying upright) opposed hands of clock.
the times i've rotated uiviews around center point, i've used layer position/anchorpoint/transform accomplish effect. changes orientation of view itself.
any help?
keller
this pretty easy in core animation. i've used pretty boring static values example, you'll want make modifications. show how move view along circular uibezierpath.
uiview *view = [uiview new]; [view setbackgroundcolor:[uicolor redcolor]]; [view setbounds:cgrectmake(0.0f, 0.0f, 50.0f, 50.0f)]; [view setcenter:[self pointaroundcircumferencefromcenter:self.view.center withradius:140.0f andangle:0.0f]]; [self.view addsubview:view]; uibezierpath *path = [uibezierpath bezierpathwithovalinrect:cgrectmake(cgrectgetmidx(self.view.frame) - 140.0f, cgrectgetmidy(self.view.frame) - 140.0f, 280.0f, 280.0f)]; cakeyframeanimation *pathanimation = [cakeyframeanimation animationwithkeypath:@"position"]; pathanimation.duration = 5.0; pathanimation.path = [path cgpath]; [view.layer addanimation:pathanimation forkey:@"curveanimation"];
and basic function generate initial center of view.
- (cgpoint)pointaroundcircumferencefromcenter:(cgpoint)center withradius:(cgfloat)radius andangle:(cgfloat)theta { cgpoint point = cgpointzero; point.x = center.x + radius * cosf(theta); point.y = center.y + radius * sinf(theta); return point; }
Comments
Post a Comment