繁体   English   中英

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

[英]how to animate transition between views?

撰写新消息时,iphone使用动画(新视图来自屏幕底部)。 我想将该动画添加到我的应用程序中。 但是我在预定义的过渡动画类型中找不到它。 如何添加?
请给我帮助。

您可以像这样切换到其他UIViewControllers:

[self presentModalViewController:yourUIViewController animated:YES];

动画的类型很多,例如...

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

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

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

这是您可以在不同的视图之间进行动画过渡的方式,需要一定的延迟。

- (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];
}

希望对您有帮助。

这是您需要的:

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

在您的情况下,您需要指定此模式转换样式以使其从底部出现:

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

您不应该直接处理视图。 顶级视图应该具有关联的视图控制器,并且该控制器将为您进行转换(例如,使用presentModalViewController:animated:方法)。

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


        }

       - (void) buttonTouch 

称为此方法,它将显示myView,该myView将从屏幕的底部滑动到顶部,例如Mail Composer或Message Composer Effect。

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

        -(void) dismissmyView 

调用此方法时,将关闭或取消当前的ModalView
即myView

暂无
暂无

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

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