ios - How To Get A Perfect Position Of Rotating View? -
i have 1 view , rotating view using cabasicanimation
. problem how perfect position of view while rotating. have tried many type of codes can't got perfect position during rotation of view.
cabasicanimation *rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; nsnumber *currentangle = [circleview.layer.presentationlayer valueforkeypath:@"transform.rotation"]; rotationanimation.fromvalue = currentangle; rotationanimation.tovalue = @(50*m_pi); rotationanimation.duration = 50.0f; // might fast rotationanimation.repeatcount = huge_valf; // huge_valf defined in math.h import [circleview.layer addanimation:rotationanimation forkey:@"rotationanimationleft"];
i using code rotating view.
i have attached 1 photo of view.
thank in advance please if know.
to view's parameters during animation should use view.layer.presentationlayer
added:
in order coordinate of top left corner of view, use following code:
- (cgpoint)currenttopleftpointoftheview:(uiview *)view { cgrect rect = view.bounds; rect.origin.x = view.center.x - 0.5 * cgrectgetwidth(rect); rect.origin.y = view.center.y - 0.5 * cgrectgetheight(rect); cgpoint originaltopleftcorner = cgpointmake(cgrectgetminx(rect), cgrectgetminy(rect)); cgpoint rectcenter = cgpointmake(cgrectgetmidx(rect), cgrectgetmidy(rect)); cgfloat radius = sqrt(pow(rectcenter.x - originaltopleftcorner.x, 2.0) + pow(rectcenter.y - originaltopleftcorner.y, 2.0)); cgfloat originalangle = m_pi - acos((rectcenter.x - originaltopleftcorner.x) / radius); catransform3d currenttransform = ((calayer *)view.layer.presentationlayer).transform; cgfloat rotation = atan2(currenttransform.m12, currenttransform.m11); cgfloat resultangle = originalangle - rotation; cgpoint currenttopleftcorner = cgpointmake(round(rectcenter.x + cos(resultangle) * radius), round(rectcenter.y - sin(resultangle) * radius)); return currenttopleftcorner; }
resulting cgpoint
coordinate of top left corner of (rotated) view relative superview.
Comments
Post a Comment