我想使用一系列图像为pushViewController
的动画创建自定义动画。
我已经完成了这一点,currentViewController
覆盖了我想要的图像,但我不知道当试图颠倒nextViewController
时,我是否有可能揭示- (IBAction)nextAction:(id)sender {
UIImage* img1 = [UIImage imageNamed:@"image-1.png"];
UIImage* img2 = [UIImage imageNamed:@"image-2.png"];
UIImage* img3 = [UIImage imageNamed:@"image-3.png"];
UIImage* img4 = [UIImage imageNamed:@"image-4.png"];
UIImage* img5 = [UIImage imageNamed:@"image-5.png"];
NSArray *animationImages = [NSArray arrayWithObjects:img1,img2,img3,img4,img5,nil];
CALayer *myLayer = [CALayer layer];
myLayer.bounds = CGRectMake(0.0, 0.0, 320.0, 480.0);
myLayer.position = self.view.center; //CGPointMake(0.0 ,0.0);
CAKeyframeAnimation *animationSequence = [CAKeyframeAnimation animationWithKeyPath: @"contents"];
animationSequence.calculationMode = kCAAnimationLinear;
animationSequence.autoreverses = NO;
animationSequence.duration = 0.4;
animationSequence.delegate = self;
animationSequence.repeatCount = 1; //HUGE_VALF;
NSMutableArray *animationSequenceArray = [[NSMutableArray alloc] init];
for (UIImage *image in animationImages)
{
[animationSequenceArray addObject:(id)image.CGImage];
}
animationSequence.values = animationSequenceArray;
[myLayer addAnimation:animationSequence forKey:@"contents"];
[self.view.layer addSublayer:myLayer];
}
- (void)animationDidStop:(CAAnimation*)animation finished:(BOOL)finished {
NextViewController *nextViewController;
nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
nextViewController.title = @"next";
[self.navigationController pushViewController:nextViewController animated:NO];
[nextViewController release];
}
的顺序动画图片。
到目前为止,我有以下
IBAction
当用户按下按钮时会执行nextAction
nextViewController
,并且图像会在当前视图的顶部进行动画处理。
我想要实现的是在图像位于顶部之后,按下图像下的nextViewController
并反转动画,以便显示{{1}}。
我希望这是有道理的。就像拍张照片一样,在照片顶部放置一些卡片,然后取出显示不同照片的卡片。
张志贤
答案 0 :(得分:0)
不是将动画图层添加到当前viewController上,而是将该图层直接添加到当前的keyWindow上。这将隐藏您当前的viewController。
[[[UIApplication sharedApplication] keyWindow] layer addSublayer:myLayer];
完成动画的前半部分(换句话说,完成前向顺序完成动画后),删除动画层。用新的替换viewController并再次将第二个动画层添加到keyWindow上 - 现在开始动画的后半部分。完成后,从keyWindow中删除动画层。
根据应用程序的结构,您还可以使用rootViewController,它有效地位于您的其他viewControllers下面,作为动画层的superview / superlayer。
[[[[UIApplication sharedApplication] rootViewController] view] layer addSublayer:myLayer];