我需要一个带有振荡动画的视图来进入屏幕,最后,动画应该以自然的方式停止(减少振荡 - 钟摆效果)。我在屏幕上方添加了子视图,以便视图在需要时旋转到屏幕中。添加子视图的代码是:
myView.layer.anchorPoint = CGPointMake(1.0, 0.0);
[[self view] addSubview:myView];
[myView setHidden:YES];
// Rotate 75 degrees to hide it off screen
CGAffineTransform rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, DEGREES_RADIANS(75));
bannerView.transform = rotationTransform;
bannerView.center = CGPointMake(((self.view.bounds.size.width)/2.0), -5.0);
[self performSelector:@selector(animateSwing) withObject:nil afterDelay:3.0];
我试图实现这一点的方式是,视图应该旋转一个完整的半圆并向后旋转,然后旋转一个半圆,最后使用 EaseOut 动画曲线在所需的点停止。我的方法的代码animateSwing()
如下:
- (void)animateSwing {
NSLog(@"ANIMATING");
[myView setHidden:NO];
CGAffineTransform swingTransform = CGAffineTransformIdentity;
swingTransform = CGAffineTransformRotate(swingTransform, DEGREES_RADIANS(-20));
[UIView animateWithDuration:0.30
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
[UIView setAnimationRepeatCount:1.5];
[UIView setAnimationRepeatAutoreverses:YES];
myView.transform = swingTransform;
}completion:^(BOOL finished){
[UIView animateWithDuration:0.10
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
myView.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(0));
}completion:^(BOOL Finished){
}];
}];
}
由于某种原因,上面的代码不起作用。如果我不链接动画,代码将执行半圆例程。但是,如果我像上面那样链接动画,它只会在所需点周围振荡一点,然后突然结束。
请建议对此代码的修复或建议一种实现所需动画的方法
谢谢