iPhone加载视图"幻灯片效果"

Fre*_*ins 4 iphone core-animation objective-c uiview uiviewanimation

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

在此输入图像描述

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

更新:

我尝试过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){


                     }];
}
Run Code Online (Sandbox Code Playgroud)

为什么加载视图在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];
}
Run Code Online (Sandbox Code Playgroud)

jam*_*ack 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){


                 }];
Run Code Online (Sandbox Code Playgroud)