代码之家  ›  专栏  ›  技术社区  ›  Dutchie432

Iphone SDK-动画子视图

  •  3
  • Dutchie432  · 技术社区  · 16 年前

    我想在显示视图时,将选项窗格(位于主视图顶部)翻转到位。我正在使用代码,我得到了一个奇怪的结果。

    有人能解释一下这个话题吗?

    - (void)viewDidLoad {
        [super viewDidLoad];
        optionsPane=[[OptionsPaneController alloc] initWithNibName:@"OptionsPane" bundle:nil];
    }
    
    - (void)viewWillAppear:(BOOL)animated {
    
        [optionsPane.view removeFromSuperview];
        [self checkOptionsVisible];
    }
    
    -(void)checkOptionsVisible{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5]; 
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:[optionsPane view] cache:YES];
        [[self view] addSubview:[optionsPane view]];
        [theWebView setFrame:CGRectMake(0,87,320,230)];
        [[optionsPane view] setFrame:CGRectMake(0,0,320,87)];
        [UIView commitAnimations];      
    }
    
    4 回复  |  直到 13 年前
        1
  •  1
  •   Boiler Bill    16 年前

    SDK

    警告:如果属于视图控制器的视图直接添加到视图层次结构中,视图控制器将不会收到此消息。如果在视图层次结构中插入或添加视图,并且该视图具有视图控制器,则应直接向关联的视图控制器发送此消息。未能向视图控制器发送此消息将阻止显示任何关联动画。

        2
  •  0
  •   Corey Floyd    16 年前

    根据您的情况更新:

    1. 后景

    2. 后视图(选项窗格)为100像素

    按常规将主视图添加到背景视图。

    将前视图添加到要显示选项窗格的后视图中。

    确保前视图和后视图具有相同的框架。

    使用与下面相同的代码,使用翻转前视图和后视图的方法。


    原始答案

    1. 后景

    2. 后视图

    “backing”视图仅保留其他2个,因为它们在下面的翻转方法中来回翻转。我将它们都放在backingViewController中:

    - (void)displayBack{
    
        //parent controller is an ivar so the sub-view controllers know who their daddy is
        backController.parentController = self;
    
    
        [UIView beginAnimations:nil context:@"flipTransitionToBack"];
        [UIView setAnimationDuration:1.2];
    
        //note self.view IS the backing view
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    
        //remove the front view
        [[frontController view] removeFromSuperview];
        //add the back view view
        [self.view addSubview:[backController view]];
        [UIView commitAnimations];
    
        //giving a heads up to the view that is about to come on screen
        [backController viewWillAppear:YES];
    
    }
    
    
    
    - (void)displayFront{
    
        [UIView beginAnimations:nil context:@"flipTransitionToFront"];
        [UIView setAnimationDuration:1.2];
    
        [UIView setAnimationDelegate:self];
    
        //I'm interested in knowing this has happened
        [UIView setAnimationDidStopSelector:@selector(flipAnimationDidEndWithID:finished:context:)];
    
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
        //remove back view
        [[backController view] removeFromSuperview];
        //add the front view
        [self.view addSubview:[frontController view]];
        [UIView commitAnimations];
    
    }  
    
        3
  •  0
  •   Skirwan    16 年前

    如果看不到更多的代码,就很难准确地知道发生了什么,但是如果在viewDidLoad中访问Options Pane.view,可能会得到想要的结果(您不需要对其执行任何操作,只需访问属性即可强制加载)。

        4
  •  0
  •   David Salzer    16 年前

    如果我理解你的解释,前几天我也遇到了类似的问题。

    在第一次加载时,viewDidLoad首先触发。加载nib文件所需的时间比视图自动启动所需的时间稍长。

    在此后的任何加载中,viewDidLoad都不会启动,让viewDidLoad看起来像是完成了它忠实的翻转工作。

    怎么办?

    另一个选项(我知道是丑陋的一个)是调用checkOptionsVisible来查看viewDidLoad。
    如果没有帮助,我会考虑一个计时器作为黑客-如果要求允许它。