objective c - Rotating NSView around center -


i'm trying animate rotation of nsview around center, keeps shifting side side during rotation. causing this?

-(void)startrefreshanimation {      [nsanimationcontext begingrouping];     [[nsanimationcontext currentcontext] setduration:1.0];     [[nsanimationcontext currentcontext] settimingfunction:[camediatimingfunction functionwithname:kcamediatimingfunctionlinear]];     [nsanimationcontext currentcontext].completionhandler = ^{ [self startrefreshanimation]; };     [[view animator] setframecenterrotation:previousrotation - 90.0];     previousrotation += -90.0;     [nsanimationcontext endgrouping];  } 

shift during rotation:

enter image description here

shift down during rotation:

enter image description here

from documentation:

if application has altered layer’s anchorpoint property, behavior undefined. sending message view not managing core animation layer causes exception.

https://developer.apple.com/library/mac/#documentation/cocoa/reference/applicationkit/classes/nsview_class/reference/nsview.html

is view managing calayer unmodified anchor point?

edit

i setup similar code @ got exact same results. no adjust of origin or anchor point resolve problem. theory particular method contains bugs (does autolayout), or works in way don't anticipate. achieved correct effect using cabasicanimation.

/* setup */  ....      _view.layer.anchorpoint = cgpointmake(0.5f, 0.5f);      _view.layer.position = ...      [self startrefreshanimation]; }  - (void)animationdidstop:(caanimation *)anim finished:(bool)flag {     [self startrefreshanimation]; }  -(void)startrefreshanimation {      cabasicanimation *anim2 = [cabasicanimation animationwithkeypath:@"transform.rotation"];     anim2.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctionlinear];     anim2.fromvalue = [nsnumber numberwithfloat:previousrotation * (m_pi / 180.0f)];     anim2.tovalue = [nsnumber numberwithfloat:(previousrotation + 90.0f) * (m_pi / 180.0f)];     previousrotation = previousrotation + 90.0f;     anim2.duration = 1.0f;     anim2.delegate = self;     [_view.layer addanimation:anim forkey:@"transform"]; } 

Comments