如果我调用动画,如何创建一个反转动画的方法?在我的项目中,我有一个UIViewController和这个控制器的子视图,它可以完成所有的背景动画。动画的作用并不是很重要。它只是让应用程序打开时出现一些矩形:
-(void)rectBottomAnimation
{
NSLog(@"ANIMATION START");
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
for (int xcord = 0; xcord <= screenWidth; xcord += 6) {
//BOTTOM
[self newRectWithX:xcord y:screenHeight height:0];
CABasicAnimation* fromBottomAnimation = [CABasicAnimation animationWithKeyPath: @"bounds"];
fromBottomAnimation.fromValue = [NSValue valueWithCGRect: _rectangle];
fromBottomAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(xcord, 0, 7, -(screenHeight)/1.4)];
fromBottomAnimation.duration = 0.3;
fromBottomAnimation.fillMode = kCAFillModeForwards;
fromBottomAnimation.removedOnCompletion = NO;
[_myLayer addAnimation: fromBottomAnimation forKey: @"resize"];
}
}
所以问题是:方法看起来是什么样的,当按下按钮时会反转这个动画?