アニメーションの途中でUiimageViewをアニメーション化します
-
12-12-2019 - |
質問
画面を横切って左に移動しているオブジェクトがあります。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:7.8];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
myImageview.layer.position = CGPointMake(20, myImageView.layer.position.y);
[UIView commitAnimations];
.
アニメーションがまだ起こっている間でさえ、Xcodeはすでにイメージの場所を最終的な目的地としてマークし、動画のタッチを検出するために、PresentationLayerを使用する必要があります:
- (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];
}
}
.
私はそれが継続している間に画像が上がるのを望みます。 誰もこれを達成するための方法を知っていますか?
ありがとうございました!
解決
アニメーションオプションUIViewAnimationOptionBeginFromCurrentState
を設定しましたか?
(iOS 4で導入されたブロックベースのアニメーションメソッドのオプションであるため、私はオプションと言います。>
TouchesBeganは(ブロックアニメーションを使用して):
- (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 animateWithDuration:0.5 delay:0.0 options:(UIViewAnimationOptionCurveLinear & UIViewAnimationOptionBeginFromCurrentState) animations:^{
myImageView.layer.position = CGPointMake( myImageView.layer.position.x, mouse.layer.position.y - 40);
}completion:^(BOOL complete){
//
}];
}
}
.
それを使用する場合は、必要なFinal [UIView setAnimationBeginsFromCurrentState:YES]
とx
座標を指定できるため、オブジェクトがその位置にタッチされた時点から進む。
所属していません StackOverflow