【问题标题】:IOS,when an UIView get fully loadedIOS,当 UIView 完全加载时
【发布时间】:2013-07-26 07:30:29
【问题描述】:

我有一个 PlayPageViewController 作为rootViewControllerPlayPageViewController 将在方法调用 editPages() 中显示 3D 模型和 UIImages,这需要几秒钟的等待时间。

我只想在开始时添加一个 loadingView,当 PlayPageViewController 完全加载时它会消失。

这是我的解决方案:

  1. 使用 activityIndi​​cator 添加 loadingView。
  2. 当loadingView加载完毕,我就开始实现

但好像没用

    STLoadingViewController *loadingView = 
     [[STLoadingViewController alloc]initWithNibName:@"STLoadingViewController" 
                                              bundle:nil];
    loadingView.view.frame=CGRectMake(0, 0, 1024, 768);
    [self.view insertSubview:loadingView.view atIndex:3];

    if(loadingView.isViewLoaded && loadingView.view.window)
    {
        [self.view insertSubview:self.playPageViewController.view atIndex:4];
        [self.playPageViewController setEditingPage:pageIndex];
        [loadingView.view removeFromSuperview];
    }

【问题讨论】:

  • 您能添加更多上下文吗?上面的代码在哪里执行?您是在后台还是在主线程中加载模型?你的视图控制器的设置到底是什么样的? Apple 建议显示占位符图像并在后台加载内容,以确保您的应用始终响应。
  • 1.上面的代码在rootViewController的ViewLoad()中执行2.我想我在主线程中加载了模型,为什么它会持续几秒钟。3。我的 viewController 的设置只是新的图像视图、模型视图并将它们添加到 self.view 中,就是这样。顺便说一句,我如何在背景中加载模型

标签: ios objective-c addsubview


【解决方案1】:

当调用此方法时,您必须执行各自的方法来调用viewDidAppear 方法,所有出现的任务都已完成。

【讨论】:

    【解决方案2】:

    ViewLoad() 方法是什么?你的意思是viewDidLoad:?您可以在情节提要中设置所有视图,包括包含活动指示器的视图。此时不要加载模型,而是等到viewDidLoad: 被调用。此时您可以使用Grand Central Dispatch 开始加载模型。它可能看起来有点像这样:

    - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
        // You need to setup the activity indicator outlet in the storyboard
        [_activityIndicator startAnimating];
    }
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            // Do the expensive work on the background
            [NSThread sleepForTimeInterval:5.0f];
            // All UI related operations must be performed on the main thread!
            dispatch_async(dispatch_get_main_queue(), ^{\
                // Replace the view containing the activity indicator with the view of your model.
                [_activityIndicator stopAnimating];
                NSLog(@"STOP");
            });
        });
    }
    

    编辑:链接似乎已关闭。这可能是由于开发中心当前存在的问题。您可以在 Xcode Organizer 的文档窗格中找到文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多