我有一个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 *********/
}发布于 2013-04-01 21:32:14
如何让UIProgressView在调用viewDidLoad方法时立即显示,并在viewDidLoad方法完成时结束?
当调用viewDidLoad时,视图还没有出现在屏幕上。在viewDidLoad之后,您将看到viewWillAppear,然后是viewDidAppear被调用。
而且,如果你有一个长时间运行的viewDidLoad,它会阻塞你的主线程,所以你的进度条不会更新。
当你这样做的时候:
[self performSelectorOnMainThread:@selector(updateProgressBar) withObject:nil waitUntilDone:NO]; 由于您在主线程上,因此指定waitUntilDone将使您的请求排队,并在稍后进行处理,可能是在您的viewDidLoad完成之后。
要做你想做的事情,你需要更多的异步代码。
发布于 2013-04-01 21:32:39
viewDidLoad在主循环、主线程上执行。这就是用户界面线程。结束后,界面上的任何更改都不会显示。所以,这是正常的行为。
选择器updateProgressBar将在同一线程(主线程)上的viewDidLoad结束后执行。
只使用viewDidLoad进行初始化,然后在后台线程上执行进程,在主线程(即接口线程)上执行progressView更改。
发布于 2018-12-13 21:57:17
在主线程(这是您的默认线程)上添加:
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate distantPast]];这将给主循环一次机会,然后返回到您的代码。
https://stackoverflow.com/questions/15744230
复制相似问题