gpt4 book ai didi

iphone - UIProgressView 不显示

转载 作者:行者123 更新时间:2023-11-29 13:16:15 25 4
gpt4 key购买 nike

我有一个 UIProgressView 我想在我的 GLKViewController 上运行,而其余代码正在由 iOS 加载。我已将 UIProgressView 放入我的“viewDidLoad”方法中。在 viewDidLoad 方法加载所有代码之前,UIProgressView 不会显示。如何让 UIProgressView 在调用 viewDidLoad 方法时立即显示并在 viewDidLoad 方法完成时结束?

- (void)viewDidLoad
{
[super viewDidLoad];

// Progress Bar
[threadProgressView setProgress: 0.0];
[self performSelectorOnMainThread:@selector(updateProgressBar) withObject:nil waitUntilDone:NO];

// Disbale iPhone from locking
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

// Set up context to use Open GL ES
self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

if (!self.context) {
NSLog(@"Failed to create ES context");
}

// Create a view to display the Open GL ES content
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;

/******** Default Settings **********/
m_kf = 0; // The current keyframe ID.
m_avPos = GLKVector3Make(0.0f, 0.0f, -35.0f); // Where to put the avata.
m_camPos = GLKVector3Make(0.0f, 10.0f, -35.0f); // The camera orbits this point.
m_camDist = 30.0f; // Distance of camera from the orbit point.

/******** Set up open gl ***********/
[self setupGL];

/********* TOUCH IMPLEMENTATION *********/

// Pinch recongizer detects pinches and is used to zoom in/out
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDetected:)];
[self.view addGestureRecognizer:pinchRecognizer];

// Pan recognizer, used to rotate around the x and y axis
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
[self.view addGestureRecognizer:panRecognizer];

/********* END TOUCH IMPLEMENTATION *********/

}

最佳答案

How can I get the UIProgressView to display as soon as the viewDidLoad method is called and end when the viewDidLoad method is finished?

viewDidLoad 被调用时, View 还没有出现在屏幕上。在 viewDidLoad 之后,您将看到 viewWillAppear 然后调用 viewDidAppear

而且如果你有一个长时间运行的 viewDidLoad 它会阻塞你的主线程,所以你的进度条不会得到更新。
当你这样做时:

 [self performSelectorOnMainThread:@selector(updateProgressBar) withObject:nil waitUntilDone:NO];    

由于您在主线程上,指定 waitUntilDone 会将您的请求排队并稍后处理,可能在您的 viewDidLoad 完成之后。

为了做你想做的事,你将需要更多的异步代码。

关于iphone - UIProgressView 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15744230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com