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