【问题标题】:How to do "pushviewcontroller" animation WITHOUT using pushviewcontroller?如何在不使用 pushviewcontroller 的情况下制作“pushviewcontroller”动画?
【发布时间】:2011-07-11 13:35:29
【问题描述】:

我想做类似 NavigationController pushviewcontroller 的动画。 但我没有 NavigationController,我不想制作它。

所以我想问是否可以在 UIViewController 中做动画?谢谢!


哦忘了说,我想在点击按钮后切换视图。 现在使用 presentModalViewController,但我不喜欢它的动画..

【问题讨论】:

    标签: ios animation uiview navigationcontroller pushviewcontroller


    【解决方案1】:

    您可以为子视图的 origin 属性设置动画,使其在添加到主视图后沿 x 轴减小。

    编辑:

    使用这样的东西:

    // retrieve the screen bounds
    CGRect sBounds = [[UIScreen mainScreen] bounds];
    // the origin point is just on the right of the screen
    CGRect newFrame = CGRectMake(sBounds.size.width,
                                 0.0,
                                 sBounds.size.width,
                                 sBounds.size.height);
    // set your view frame
    [mySecondView setFrame:newFrame];
    // add it to the main view
    [mainView addSubview:mySecondView];
    // then animate your view
    [UIView animateWithDuration:0.5     // set the interval you want
                     animations:^{
                         mySecondView.frame.origin = sBounds.origin;
                     }
    ];
    

    【讨论】:

    • 你的意思是让我的第二个视图动画到第一个视图?代码上怎么做?
    • stackoverflow.com/questions/5577077/… 所以我必须先添加子视图(我的第二个视图)然后使用 [UIView animateWithDuration:1.2 动画:^{ SecondView.view.frame = CGRectMake(320, 0, 320, 480 ); }];对吗?
    • 是的,你是对的,以防万一你不想使用导航控制器提供的设施。要理解的是你修改了一个视图属性,使用UIView的动画设施
    • 谢谢,我稍后试试。 btw [[UIScreen mainScreen] bounds];这是什么意思?
    • 很好,关于延迟,了解NSTimer 及其类方法之一:-(NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats;
    【解决方案2】:

    我会使用导航控制器并隐藏导航栏,但如果您不想这样做,您可以使用 [UIView beginAnimantion: @"myAnimation" withContext: nil]; 在视图之间切换并更改框架或原点。

    【讨论】:

      猜你喜欢
      • 2013-01-26
      • 1970-01-01
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      相关资源
      最近更新 更多