iPhone加载视图“幻灯片效果”

时间:2011-11-03 03:31:12

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

当你在我的应用程序中请求某些东西(比如按下按钮或其他任何东西)时,我想实现这一点。我希望它看起来像一个小的矩形,上面写着“loading ..”,当加载完成后它会消失“滑动效果“。我做了一个简单的模型来描述我正在努力实现的目标。你有什么暗示吗?感谢。

enter image description here

注意:我不希望拉动刷新效果(加载视图在没有屏幕滚动的情况下显示,例如在您发送评论时显示)

更新

我尝试过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];
}

3 个答案:

答案 0 :(得分:5)

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 :(得分:1)

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

然后当加载完成时(使用通知或只是调用视图的一个功能),用这种动画向上滑动:

[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)
                         }];

答案 2 :(得分:0)

你可以在微调器的帮助下完成它,你只需要查看并用你的坐标设置动画,当你点击它将在你的视图中弹出的任何对象时,在加载它之后你必须设置' - '坐标(你的弹出视图跳,它会帮助你......