我一直在寻找如何实现幸运型轮子(运行良好)的解决方案,除了我需要轮子外围的图像/标签保持水平而不随轮子旋转。我实现了以下内容,但标签(在本例中为红色椭圆)没有保持水平。
我附上了在屏幕上构建红色椭圆的代码:
CGFloat cita = 0;
for(int i = 1; i < 2; ++i)
{
CGFloat smallCircleRadius = bigCircleRadius / 8.0;
for (int i = 0; i < 8; i++)
{
CGPoint smallCircleCenter = CGPointMake(wheelCenter.x + bigCircleRadius * cos(cita) - smallCircleRadius/2.0 , wheelCenter.y + bigCircleRadius * sin(cita) - smallCircleRadius / 2.0 );
CGRect smallCircleRect = CGRectMake(smallCircleCenter.x,smallCircleCenter.y,smallCircleRadius * 2,smallCircleRadius);
cita += M_PI / 4.0;
CAShapeLayer *l = [CAShapeLayer layer];
UIBezierPath * p1 = [UIBezierPath bezierPathWithOvalInRect:smallCircleRect];
l.path = p1.CGPath;
l.strokeColor = [[UIColor redColor] CGColor];
l.fillColor = [[UIColor redColor] CGColor];
l.lineWidth = 3.0;
l.anchorPoint = CGPointMake(.5, .5);
[self.emoticonsArray addObject:l];
[self.baseWheel.layer addSublayer:l];
}
}
下面是旋转轮子的函数;我正在编写为标签进行旋转的代码行——我显然在这里做错了,但我不知道是什么。非常感谢任何指导。
-(void)spin:(double)delta
{
currentAngle = currentAngle + delta;
CATransform3D transform = CATransform3DMakeRotation(currentAngle, 0, 0, 1);
[self.baseWheel.layer setTransform:transform];
// rotate the red labels here.
for (CAShapeLayer * l in self.emoticonsArray)
{
CGPoint miniWheelCenter = [l convertPoint:l.position toLayer:self.baseWheel.layer.superlayer];
// !! something wrong here!! but what?
CATransform3D t_l = CATransform3DMakeRotation(-currentAngle, miniWheelCenter.x/2, miniWheelCenter.y/2, 1);
[l setTransform:t_l];
}
}