zoukankan      html  css  js  c++  java
  • 转:在两个页面间翻转设置Animation动作的一些总结

    今天碰到两个页面之间翻转的动作设计问题,发现了一些问题,故做个总结,很多都写在注释部分:

    1、首先,我们来手动创建两个view以及相应的viewController。是手动,不是用IB

    (1)刚开始只加载一个view(第二个),若两个同时加载,第二个页面可能不能完全被遮挡。第二个页面可以通过翻转来显示。

    	[window addSubview:secodViewController.view];
    

    2、要求:每个view页面都有一个按钮,按下之后切换到另一个页面,要求有炫一点的切换效果,故要对Animation属性进行一些设置

     (1)helloWorldViewController.m:

    mySecondViewController *SecondViewController;
     - (void) btnClicked:(id)sender
     {
         SecondViewController=[[mySecondViewController alloc]
          initWithNibName:@"SecondViewController"
          bundle:nil];
         
         //---创建一个翻转页面的动画---
     //---这个动画的forView属性是UIView,应用与整个view,跟有几个页面无关,只有一个页面仍旧有效果出来---
         [UIView beginAnimations:@"flipping view" context:nil];
         [UIView setAnimationDuration:1];
         [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
         [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft//与Left相对
                                forView:self.view.superview cache:YES];//forView:UIView
         
     //---remove the current view; essentially hiding the view---
         
         [self.view removeFromSuperview];
    //不加这句也可以正常运行,不过程序会一直叠加view,内存浪费!
         [UIView commitAnimations];//执行动画
     
     
     }

    (2)secondViewController.m:

    -(IBAction) btnClicked:(id)sender
     {
         helloWorldViewController=[[helloWorldApp alloc]initWithNibName:@"helloWorldApp"
                                                                 bundle:nil];
         //实例化一个控制器,因为下面addSubView要用到
         UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil 
                                                     message:@"你按了SecondView的按钮!"
                                                     delegate:self 
                                            cancelButtonTitle:@"done"
                                            otherButtonTitles:nil];
         [alert show];
         [alert release];
         //---创建一个翻转页面的动画---
         [UIView beginAnimations:@"flipping view" context:nil];
         [UIView setAnimationDuration:1];
         [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
         [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight//与Left相对
                                forView:self.view.superview cache:YES];
         
         //---remove the current view; essentially hiding the view---
         [self.view addSubview:helloWorldViewController.view];    
         
         [UIView commitAnimations];//执行动画
     
         
     }

    UIView是UIWindow、UIScrollBar等的超类,所以这里的self.view.superview就是UIView。所以这里的Animation动画是针对UIView而言的,而不是当前view页面,我觉得这点是最关键的。只有理解了这点,对与该remove还是addsubview就不会晕了。

    其实,道理很简单,用土话总结一下:先加载ViewB->在ViewB的Action里面设置好动画,把ViewA加到ViewA (addSubView)->转到了ViewA,设置动画,removeFromSuperView(这里的super就是指ViewA,因为刚刚是SubView,Sub,子,与父对应)->转到ViewA.....循环下去。用更土的话讲,就是第二加载的View要自杀完才回到第一加载的View。

    转:http://www.cnblogs.com/wengzilin/archive/2012/03/01/Animation.html

  • 相关阅读:
    oracle 插入timestamp
    ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException
    把工程部署在tomcat的root路径下
    修改tomcat 启动45秒
    struts2 ,web.xml中配置为/*.action,运行报错Invalid <url-pattern> /*.action in filter mapp
    解决Tomcat 7遇到StackOverflowError的异常
    eclipse 安装svn插件
    WP8_ListBox的用法
    WP8_检测列表是否滑动
    WP8_访问ListBox中的Item项中的某个元素
  • 原文地址:https://www.cnblogs.com/ygm900/p/3151842.html
Copyright © 2011-2022 走看看