【问题标题】:iPhone loading view "slide effect"iPhone加载视图“幻灯片效果”
【发布时间】:2011-12-20 20:34:05
【问题描述】:

当您在我的应用程序中请求某些内容(例如按下按钮或其他任何内容)时,我希望实现这一点上滑效果”。我制作了一个简单的模型来很好地描述我想要实现的目标。你对我有什么暗示吗?谢谢。

注意:我不想拉动刷新效果(加载视图出现时屏幕不滚动,例如当您发送评论时出现)

更新:

我已经尝试过 Cirrostratus 代码:

- (IBAction)displayLoadingScreen:(id)sender
{
    NSLog(@"pressed");
    UIView *loadingView = [[UIView alloc] init];
    loadingView.frame = CGRectMake(0,-40,320,40);
    [loadingView setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:loadingView];
    //animate in within some method called when loading starts
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,0,320,40);
                     } 
                     completion:^(BOOL finished) {
                     }];
    for (int i = 0; i < 10000; i++) {
        NSLog(@"%d", i);
    }
    //animate out within some method called when loading ends
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,-40,320,40);
                     } 
                     completion:^(BOOL finished){


                     }];
}

为什么加载视图在 for 循环之后滑动?如果你尝试一下,在它打印 for 循环之前和之后执行两个动画。想法?

更新 2

- (void)stopLoading {
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,-40,320,40);
                     } 
                     completion:^(BOOL finished){
                     }];
}

- (void)startLoading {
    loadingView.frame = CGRectMake(0,-40,320,40);
    [loadingView setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:loadingView];
    //animate in within some method called when loading starts
    [UIView animateWithDuration:1.0
                     animations:^{ 
                         loadingView.frame = CGRectMake(0,0,320,40);
                     } 
                     completion:^(BOOL finished) {
                     }];
    sleep(5);
    [self stopLoading];
}

- (IBAction)displayLoadingScreen:(id)sender
{
    NSLog(@"button pressed");
    [self startLoading];
}

【问题讨论】:

  • 尝试阅读 UIAnimation 类(并使用 QuartzCore 框架)。
  • 或者,如果您想像 Facebook 那样使用向下滑动更新功能,请考虑使用 EGOTableViewPullRefresh

标签: iphone objective-c uiview core-animation uiviewanimation


【解决方案1】:

您可以在微调器的帮助下完成,否则您只需查看并设置动画及其坐标,当您单击任何对象时,它将在您的视图中弹出,并且在完成加载后您必须设置'-'坐标(框架)为您的弹出视图跳跃它会帮助您......

【讨论】:

    【解决方案2】:

    我要做的是在您的其他视图前面添加一个视图,并使用您想要的加载设计。

    然后当加载完成时(使用通知或调用视图的函数),用那种动画向上滑动:

    [UIView animateWithDuration:0.3
                                  delay:0
                                options:UIViewAnimationOptionAllowUserInteraction
                             animations:^{
                                 //change the frame to make the view go out of the screen
                             }
                             completion:^(BOOL finished){
                                 //do whatever you want with the view (release it for instance)
                             }];
    

    【讨论】:

      【解决方案3】:
      loadingView.frame = CGRectMake(0,-40,320,40);
      [loadingView setBackgroundColor:[UIColor blueColor]];
      [self.view addSubview:loadingView];
      //animate in within some method called when loading starts
      [UIView animateWithDuration:1.0
                       animations:^{ 
                           loadingView.frame = CGRectMake(0,0,320,40);
                       } 
                       completion:^(BOOL finished){
      
      
                       }];
      //animate out within some method called when loading ends
      [UIView animateWithDuration:1.0
                       animations:^{ 
                           loadingView.frame = CGRectMake(0,-40,320,40);
                       } 
                       completion:^(BOOL finished){
      
      
                       }];
      

      【讨论】:

      • 在我的回答中,我告诉你将这些动画放在单独的方法中,一个在加载开始时调用,一个在加载结束时调用。循环在动画完成之前执行,因为动画需要 1 秒的执行时间,这是在其他代码继续执行时完成的。所以,回顾一下——不要在同一个方法中使用两个动画。在加载实际开始时调用一个,在加载实际完成时调用另一个,一切都会好起来的。
      • 感谢您的耐心等待,但它对我不起作用。请参阅我的新更新。为什么执行的第一条语句是sleep 而不是我在动画中的第一张幻灯片?
      • 如果您实际加载的数据与使用睡眠不同。你永远不应该在 iPhone 程序中真正使用睡眠。取出睡眠并执行此操作: [UIView animateWithDuration:1.0 动画:^{ loadingView.frame = CGRectMake(0,0,320,40); } 完成:^(BOOL 完成){ [UIView animateWithDuration:1.0 动画:^{ loadingView.frame = CGRectMake(0,-40,320,40); } 完成:^(BOOL 完成){ }]; }];
      • 我使用sleep 进行测试。动画效果很好,但我希望视图滑入,停留几秒钟(在请求期间),当请求完成时它会滑出。想法?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-11
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 2012-07-02
      相关资源
      最近更新 更多