这是我用来旋转图层的代码:
CALayer *myLayer = [imageVIEw layer];CGfloat myRotationAngle = -M_PI_2;NSNumber *rotationAtStart = [myLayer valueForKeyPath:@"transform.rotation"];CAtransform3D myRotationtransform = CAtransform3DRotate(myLayer.transform,myRotationAngle,0.0,1.0);myLayer.transform = myRotationtransform; CABasicAnimation *myAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];myAnimation.duration = 1.0;myAnimation.fromValue = rotationAtStart;myAnimation.tovalue = [NSNumber numberWithfloat:([rotationAtStart floatValue] + myRotationAngle)];[myLayer addAnimation:myAnimation forKey:@"transform.rotation"];myLayer.anchorPoint = CGPointMake(0.5,0.5);[myLayer addAnimation:myAnimation forKey:@"transform.rotation"];解决方法 似乎改变某些东西的锚点也会改变它的位置.以下代码段修复了此问题:
CGPoint anchorPoint = CGPointMake(0.5,0.5); CGPoint newPoint = CGPointMake(disclosureTriangle.bounds.size.wIDth * anchorPoint.x,disclosureTriangle.bounds.size.height * anchorPoint.y); CGPoint oldPoint = CGPointMake(disclosureTriangle.bounds.size.wIDth * disclosureTriangle.layer.anchorPoint.x,disclosureTriangle.bounds.size.height * disclosureTriangle.layer.anchorPoint.y); newPoint = CGPointApplyAffinetransform(newPoint,[disclosureTriangle.layer affinetransform]); oldPoint = CGPointApplyAffinetransform(oldPoint,[disclosureTriangle.layer affinetransform]); CGPoint position = disclosureTriangle.layer.position; position.x -= oldPoint.x; position.x += newPoint.x; position.y -= oldPoint.y; position.y += newPoint.y; disclosureTriangle.layer.position = position; disclosureTriangle.layer.anchorPoint = anchorPoint;总结
以上是内存溢出为你收集整理的macos – 旋转NSImageView的CALayer 90度全部内容,希望文章能够帮你解决macos – 旋转NSImageView的CALayer 90度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)