0
我有一個向右移動在屏幕上留下了一個對象:動畫一個UIImageView在動畫中的中間
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:7.8];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myImageview.layer.position = CGPointMake(20, myImageView.layer.position.y);
[UIView commitAnimations];
我發現,即使在動畫仍然發生時,Xcode已經標誌着圖像的所在地爲最終目標,並以檢測運動圖像上的觸摸,我需要使用表示層:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
if ([myImageview.layer.presentationLayer hitTest:touchPoint]) {
NSLog(@"it's a hit!");
}
}
這部分工作。 現在,我希望圖像在按下時向上移動。 我希望圖像向上移動,同時繼續向左移動。 相反,該代碼移動圖像不僅達到,而且一路左其最終目的地:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
if ([mouse.layer.presentationLayer hitTest:touchPoint]) {
NSLog(@"it's a hit!");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myImageView.layer.position = CGPointMake(mouse.layer.position.x, myImageView.layer.position.y - 40);
[UIView commitAnimations];
}
}
我想要的圖像向上移動,同時繼續它的側向運動。 有誰知道一種方法來實現這一點?
非常感謝!
太棒了!我完全不知道的是多麼棒的選擇! – RanLearns
非常有趣,它取代了以前的動畫。我試圖讓原始動畫繼續下去,因爲它隻影響x軸,並沿途將動畫添加到y軸。這絕對是一個有趣的選項,但仍然不能正常工作,因爲它不僅將我的imageView向上移動,而且還將其發送到左側的最終目的地。非常感謝!將玩這個新的選項。 =) – RanLearns
您確實需要重新計算和更改動畫參數才能獲得所需的最終結果。 –