活动指示器没有立即开始动画

发布于 2024-12-21 12:33:17 字数 632 浏览 0 评论 0原文

我初始化一个活动指示器,并在按下按钮的操作中启动它的动画并调用下一个要显示的视图。

-(IBAction) downloadButtonPressed:(id)sender {

    NSLog(@"Download Button Pressed");
    indicator.hidden = NO;
    [indicator startAnimating];

    if (addviewcontroller == nil)
        addviewcontroller = [[AddViewController alloc]init];
    [self.view addSubview:addviewcontroller.view];

    [addviewcontroller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:addviewcontroller animated:YES];

}

当我按下按钮时,活动指示器不会立即启动。它在调用另一个视图时启动。该指示器会显示一秒钟,但是当按下按钮时,需要一些时间来加载其他视图。

我不知道为什么指示灯显示一秒钟而没有启动。

I initialize an activity indicator and in a button press action I start it animating and call the next view to display.

-(IBAction) downloadButtonPressed:(id)sender {

    NSLog(@"Download Button Pressed");
    indicator.hidden = NO;
    [indicator startAnimating];

    if (addviewcontroller == nil)
        addviewcontroller = [[AddViewController alloc]init];
    [self.view addSubview:addviewcontroller.view];

    [addviewcontroller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:addviewcontroller animated:YES];

}

When I press the button, the activity indicator doesn't start immediately. It starts when the other view is called. The indicator is displayed for a second, but when the button is pressed it takes some time to load the other view.

I dont know why the indicator shows for a second without starting.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

永不分离 2024-12-28 12:33:17

试试这个:

-(IBAction) downloadButtonPressed:(id)sender 
{
    NSLog(@"Download Button Pressed");
    indicator.hidden = NO;
    [indicator startAnimating];
    [self performSelector:@selector(showController) withObject:nil afterDelay:0.1f];
}

- (void)showController {

    if (addviewcontroller == nil)
        addviewcontroller = [[AddViewController alloc]init];
    [self.view addSubview:addviewcontroller.view];

    [addviewcontroller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:addviewcontroller animated:YES];
}

应该可以解决问题;-)

编辑

我刚刚注意到您的代码中有一个问题,您添加了addviewcontroller两次。一种是将其添加为实际视图控制器的子视图,另一种是通过模态呈现另一个视图控制器。您应该从此函数中删除其中一条语句。

Try this :

-(IBAction) downloadButtonPressed:(id)sender 
{
    NSLog(@"Download Button Pressed");
    indicator.hidden = NO;
    [indicator startAnimating];
    [self performSelector:@selector(showController) withObject:nil afterDelay:0.1f];
}

- (void)showController {

    if (addviewcontroller == nil)
        addviewcontroller = [[AddViewController alloc]init];
    [self.view addSubview:addviewcontroller.view];

    [addviewcontroller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:addviewcontroller animated:YES];
}

That should do the trick ;-)

EDIT

I just noticed that there is a problem in your code, you are adding your addviewcontroller twice. One by adding it as a subview of the actual view controller, and one by modally presenting another view controller. You should remove one of the statements from this function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文