在我的应用程序中以这种方式显示不同的屏幕:
info = [[Info alloc]initWithNibName:@"Info" bundle:nil];
[self.view addSubview:info.view];
Info是UIViewController的子类,所以我只是创建它并将其添加为当前视图的子视图。
当我想解雇时,我只是这样做:
[self.view removeFromSuperview];
我不确定这是不是这样做的正确方法,但是昨天苹果公司已经在app store上发布了另一款同样用来显示视图的应用程序。
我的问题是,我如何设置视图之间的过渡动画,所以当我调用addsubview时它会做动画?
我试过了:
info = [[Info alloc]initWithNibName:@"Info" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:info.view
cache:YES];
[self.view addSubview:info.view];
[UIView commitAnimations];
但它不起作用,这不做任何事。
答案 0 :(得分:4)
这不是管理视图层次结构的正确方法。您应该使用视图控制器方法(addChildViewController:
& removeFromParentViewController
)。然后你可以使用方法transitionFromViewController:toViewController:options:animations:completion:
(或类似的东西)来做各种动画。
答案 1 :(得分:1)
添加视图控制器的视图使用此
ChildViewController * child = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:info.view
cache:YES];
[self.view addSubview:child.view];
[UIView commitAnimations];
[self addChildViewController:child];
[child release];//for NON ARC
删除视图使用此...
for (UIViewController *childVC in [self childViewControllers])
{
[childVC removeFromParentViewController];
}
[self.view removeFromSuperview];// YOU CAN ADD ANIMATIONS HERE
[self removeFromParentViewController];
希望这会对你有所帮助,对我来说这很好....
答案 2 :(得分:1)
你可以在不使用导航控制器的情况下将CATransition用于那种动画,代码是
Info *infoViewController = [[Info alloc]init];
CATransition *transition = [CATransition animation];
transition.duration = 0.50;
transition.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
UIView *containerView = self.view.window;
[containerView.layer addAnimation:transition forKey:nil];
[self presentModalViewController:infoViewController animated:NO];
像这样,您可以在不使用navigationcontroller的情况下从左到右设置视图动画。
答案 3 :(得分:0)
你可以给UIView Block Animation一个镜头。像这样:
[UIView animateWithDuration:.25 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^
{
requiredView.frame = CGRectMake(0, 300.0, 400.0, 180.0);
} completion:^(BOOL finished)
{
}];
您可以设置视图的框架并将其放置在查看坐标之外,然后相应地更改框架以设置UIView
的动画。