【问题标题】:IPhone UIToolBar UiBarButtonItem Transition problemiPhone UIToolBar UiBarButtonItem 过渡问题
【发布时间】:2009-07-19 08:03:33
【问题描述】:

当我开始从 UiView 到此视图的过渡(UIViewAnimationTransitionFlipFromLeft)时,我有一个带有 UIToolBar 的 UIView,该按钮仅在过渡结束时出现 为什么 ?请帮助我

谢谢

代码:

[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.90];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    UIViewController *coming = nil;
UIViewController *going = nil;
    UIViewAnimationTransition transition;
going = languageMenu;
coming = loadingmenu;
transition = UIViewAnimationTransitionFlipFromLeft;
   [UIView setAnimationTransition: transition forView:self.view cache:YES];

[coming viewWillAppear:YES];
[going viewWillDisappear:YES];

[going.view removeFromSuperview];
[self.view insertSubview: coming.view atIndex:0];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];

[UIView commitAnimations];

【问题讨论】:

  • 你能展示一段代码吗?
  • 如果我启用缓存:否 按钮在过渡期间出现,但一切都很慢?有什么想法吗?

标签: iphone button transition uitoolbar


【解决方案1】:

我想说这取决于您何时创建 UIToolbar 及其后退按钮,以及何时将它们添加到新视图中。

还有——为什么 viewWillAppear 和 viewWillDisappear 线需要成为动画的一部分有什么特别的原因吗?我会尝试将它们从动画中拉出来,并将 viewDidDisappear 和 viewDidAppear 移动到动画完成时调用的回调函数中;请参阅 UIView setAnimationDidStopSelector 的文档。

不确定这是否会有所帮助,但可能会。

【讨论】:

  • 感谢 Amagrammer,我将 viewWillAppear 和 viewWillDisappear 移出动画块,现在可以正常工作了 :) 谢谢!
  • 不客气!你是我在 Stack Overflow 上真正能够帮助的第一个人。
【解决方案2】:

缓存转换的工作方式是 iPhone 拍摄窗口的快照并对其进行一些转换,就好像它是图像一样。未缓存的转换实际上会在转换时重新绘制实时窗口。

您的问题似乎是拍摄快照时视图中不存在后退按钮。解决方案可能是手动添加按钮,而不是依赖导航视图控制器或其他东西。

【讨论】:

    【解决方案3】:

    这可能是两个视图之间存在差异的问题。在 IB 中查看您的两个视图的属性;您是否为两者指定了状态栏?还是只是其中之一?这可能会导致垂直偏移的差异,并且可能会导致一些我认为的问题。

    您可以通过在动画转换代码之前设置两帧相等来解决这个小问题:

    newViewController.view.frame = self.view.frame;
    

    (这也应该允许您恢复缓存:是)

    另一方面,您可能需要考虑将子视图添加到当前窗口而不是当前窗口的当前视图,因此:

    [[self.view superview] addSubview:newViewController.view];
    

    这样您可以删除对所有窗口事件的显式调用。您还需要将过渡链接到您的窗口而不是当前视图,否则动画将不起作用:

    [UIView setAnimationTransition:transition forView:self.view.superview cache:YES];
    

    我一直在为类似的问题而苦苦挣扎,最终解决了这个问题。您可能还想尝试使用 QuartzCore 基础动画:

    #import <QuartzCore/QuartzCore.h>
    
    // ...
    
        // get the view that's currently showing
        UIView *currentView = self.view;
        [currentView retain];
        // get the the underlying UIWindow, or the view containing the current view
        UIView *theWindow = [currentView superview];
    
        UIView *newView = myNewViewController.view;
        newView.frame = currentView.frame;
    
        // add subview
        [theWindow addSubview:newView];
    
        // set up an animation for the transition between the views
        CATransition *animation = [CATransition animation];
        [animation setDuration:0.8];
        [animation setType:kCATransitionPush];
        [animation setSubtype:kCATransitionFromRight];
        [animation setTimingFunction:[CAMediaTimingFunction
                functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    
        [[theWindow layer] addAnimation:animation forKey:@"SwitchToView1"];
    

    并且要转换回来,做同样的事情(当然除了相反的方向)替换你的添加子视图:

        [self.view removeFromSuperview];
    

    这样,前一个窗口将再次出现在前台,但不会触发其事件(我仍然不确定为什么)。

    我希望这能为你解决问题并帮助很多其他人。

    【讨论】: