简体   繁体   English

如何为视图之间的过渡设置动画?

[英]how to animate transition between views?

when compose a new message, iphone use an animation (new view comes from bottom of the screen). 撰写新消息时,iphone使用动画(新视图来自屏幕底部)。 I want to add that animation to my application. 我想将该动画添加到我的应用程序中。 But I can't find it in pre-define transition animation types. 但是我在预定义的过渡动画类型中找不到它。 How could I add it? 如何添加?
Please give me help. 请给我帮助。

You can switch to other UIViewControllers like this: 您可以像这样切换到其他UIViewControllers:

[self presentModalViewController:yourUIViewController animated:YES];

There are many types of animation like... 动画的类型很多,例如...

yourUIViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:yourUIViewController animated:YES];

yourUIViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:yourUIViewController animated:YES];

yourUIViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:yourUIViewController animated:YES];

This is how you can animate transition between different views with some delay. 这是您可以在不同的视图之间进行动画过渡的方式,需要一定的延迟。

- (void)viewsAction:(id)sender
{  

  First *first = [[First alloc] init];

  first.view.frame = CGRectMake(0, 0, 320, 425);

  CATransition *transitionAnimation = [CATransition animation];

  [transitionAnimation setDuration:1];

  [transitionAnimation setType:kCATransitionFade];

   [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];

   [first.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];

     [self.view addSubview:first.view]; 

     [first release];

      self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];

   }

  -(void)Second 
 {
    Second *second = [[Second alloc] init];

second.view.frame = CGRectMake(0, 0, 320, 425);

CATransition *transitionAnimation = [CATransition animation];

[transitionAnimation setDuration:1];

[transitionAnimation setType:kCATransitionPush];

[transitionAnimation setSubtype:kCATransitionFromRight];

[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];

[second.view.layer addAnimation:transitionAnimation forKey:kCATransitionPush];

[self.view addSubview:second.view]; 

  [second release];

self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
}

Hope it helps you. 希望对您有帮助。

This is what you need: 这是您需要的:

- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;

In your case you need to specify this modal transition style in order to make it come from the bottom: 在您的情况下,您需要指定此模式转换样式以使其从底部出现:

UIViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:yourUIViewController animated:YES];

You should not juggle views directly. 您不应该直接处理视图。 Top-level views should have a view controller associated, and the controller will do the transitions for you (like using the presentModalViewController:animated: method). 顶级视图应该具有关联的视图控制器,并且该控制器将为您进行转换(例如,使用presentModalViewController:animated:方法)。

              - (void) buttonTouch
        {
        myView *Obj=[[myView alloc]init];
        [self presentModalViewController:Obj animated:YES];


        }

       - (void) buttonTouch 

This method is called it will present myView which will be sliding from bottom to top of screen like Mail Composer or Message Composer Effect. 称为此方法,它将显示myView,该myView将从屏幕的底部滑动到顶部,例如Mail Composer或Message Composer Effect。

            -(void) dismissmyView
             {
               [self dismissModalViewControllerAnimated:YES];
             }  

        -(void) dismissmyView 

This method when called it will dismiss or cancels the current ModalView 调用此方法时,将关闭或取消当前的ModalView
ie myView 即myView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM