以下のような「短くて簡単な」方法はありますか?カーブはまだ を使用しているようEaseOut
です。
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
// ... do stuff here
}];
以下のような「短くて簡単な」方法はありますか?カーブはまだ を使用しているようEaseOut
です。
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView animateWithDuration:0.5 animations:^{
// ... do stuff here
}];
2 種類の UIView アニメーションを混在させています。次のいずれかのようなものを使用する必要があります。
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
// ... do stuff here
} completion:NULL];
これは、新しいブロックベースの UIView-animation API から来ました。一方、最初の行は、次のような古い UIView アニメーション API の一部です。
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
// ... do stuff here
[UIView commitAnimations];
どちらも同じことを行い、どちらも使用できます (ただし、Apple はブロックベースの API を推奨しています。これは、アニメーションの終了後にコールバックを行う方が簡単でクリーンであるためです)。
Core Animation 、 CAKeyFrameAnimation を使用して曲線ポイントを定義できます。このチュートリアルを参照してください: http://nachbaur.com/blog/core-animation-part-4
曲線ポイント p1、p2、p3、p4、および p5 を取り、隣接するポイントの各ペアの中点を見つけます。p1 と p2 の中点として m1 にラベルを付けます。m2、m3、m4 についても同様です。
コード:
CGFloat screenHeight = self.view.frame.size.height;
CGFloat screenWidth = self.view.frame.size.width;
UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(50, screenHeight, 50, 50)];
[aniView setBackgroundColor:[UIColor redColor]];
aniView.layer.cornerRadius = 25.0;
[self.view addSubview:aniView];
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:aniView.center];
[movePath addQuadCurveToPoint:CGPointMake(screenWidth-50,screenHeight-50)
controlPoint:CGPointMake(screenWidth/2,screenHeight-150)];
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil];
animGroup.duration = 2.0;
[CATransaction begin]; {
[CATransaction setCompletionBlock:^{
[aniView.layer removeAllAnimations];
[aniView removeFromSuperview];
}];
[aniView.layer addAnimation:animGroup forKey:nil];
} [CATransaction commit];
上記のコードをいくつかのメソッドにコピーして、メソッドを呼び出してみてください...