我正在尝试使用滑块围绕视图中心旋转图像,其中一个用于 x、y 和 Z 平面。我希望图像在它的框架边界(700X700)内旋转,但由于某种原因它围绕框架的边缘旋转。我尝试重置锚点,但这似乎没有任何作用。这是绕 Y 轴旋转它的代码;你会注意到锚点部分被注释掉了——它根本没有任何影响。知道我做错了什么吗?
float angleYDeg = self.ySlider.value;
float angleYRad = (angleYDeg / 180.0) * M_PI;
// Disable Animation
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithBool:YES]
forKey:kCATransactionDisableActions];
// Get Layers
CALayer *containerLayer = [[self.imageView.layer sublayers] objectAtIndex:0];
CALayer *holder = [containerLayer valueForKey:@"__holderLayer"];
//CGPoint anchor = holder.anchorPoint;
//anchor.y = self.imageView.frame.size.height/2;
//holder.anchorPoint = anchor;
// Update xAngle Value
[containerLayer setValue:[NSNumber numberWithFloat:angleYRad] forKey:@"__angleY"];
// Apply rotations
CGFloat angleX = [[containerLayer valueForKey:@"__angleX"]floatValue];
CATransform3D holderTransform = CATransform3DMakeRotation( angleX, 1.0f, 0.0f, 0.0f);
holderTransform = CATransform3DRotate(holderTransform, angleYRad, 0.0f, 1.0f, 0.0f);
holder.transform = holderTransform;
[CATransaction commit];
// Update Label
self.yValueLabel.text = [NSString stringWithFormat:@"%4.0fº", angleYDeg];