0
我已经开发为iPhone 伪 3D旋转木马,看起来很像下面的图片: 如何计算从3D旋转木马动画的视图的位置?
我基本上创造UIViews的数组,然后注册为触摸事件:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// if we're not already tracking a touch then...
if(!trackingTouch)
{
// ... track any of the new touches, we don't care which ...
trackingTouch = [touches anyObject];
}
}
虽然运动仍在注册我做到以下几点:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// if our touch moved then...
if([touches containsObject:trackingTouch])
{
// use the movement of the touch to decide
// how much to rotate the carousel
CGPoint locationNow = [trackingTouch locationInView:self];
CGPoint locationThen = [trackingTouch previousLocationInView:self];
lastAngle = currentAngle;
currentAngle += (locationNow.x - locationThen.x) * 180.0f/self.bounds.size.width;
// and update the view positions
[self setCarouselAngle:currentAngle];
}
}
当触摸结束我随后致电:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// if our touch ended then...
if([touches containsObject:trackingTouch])
{
// make sure we're no longer tracking it
trackingTouch = nil;
// and kick off the inertial animation
animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(animateAngle) userInfo:nil repeats:YES];
}
}
的animageAngle方法基本上然后调用其他方法与由视图阵列中的数除以有效360度,并使用余弦和正弦函数,以产生x和y坐标。
上述所有工作好但我有困难理解完成以下所需的数学:
- 单击视图出来的主要焦点在前面例如,在紫色的观点,即不图像
- 旋转紫观点成为关注的焦点即前
- 加载一次旋转一个新的视图控制器具有完整
我明白,我必须CA计算当前位置的视图与计划的目的地之间的角度以进行旋转,但我无法为我的生活弄清楚。
先前的困惑道歉 - 我一直在寻找这个问题,因为我已经开始失去这个阴谋。
谢谢
你将需要提供某种形式的图像来描述这一点,因为我不能形成你的情况在我的头上了良好的画面。另外,CGAffineTransform如何实现这一点,因为它只是一个二维变换?看起来你需要在这里使用CATransform3D。 –
感谢Brad回复。我在第一篇文章中误导了我,因为这不仅仅是3D效果的印象。希望图像可以帮助更多 – JordanMazurke