您可以延迟然后通过选择器调用,这将同步您的线程(但这可能不是最好的方法,您也可以使用 OperationQueue 和 GCD)。但这符合您的目的:
我使用了 NSTextField 和 NSTextView,因为在您的问题和评论中都包含这两者。
-(void)someProcess:(id)sender{
for (int i=0; i<100000; i++) {
for (int j=0; j<9000; j++) {
;
}
}
NSLog(@"someProcess ends");
}
-(void)startProgressIndicator{
[self.progressIndicator startAnimation:self];
}
-(void)stopProgressIndicator{
[self.progressIndicator stopAnimation:self];
}
-(void)hideScroll{
[self.textField setHidden:YES];
[self.scrollView setHidden:YES];
}
-(void)showScroll{
[self.textField setHidden:NO];
[self.scrollView setHidden:NO];
}
- (IBAction)button:(id)sender {
//hide scrollview
NSLog(@"hide sv");
[self hideScroll];
//start prog indi
NSLog(@"run");
[self performSelector:@selector(startProgressIndicator) withObject:self afterDelay:1];
//some process
[self someProcess:nil];
//stop prog indi
NSLog(@"stop");
[self performSelector:@selector(stopProgressIndicator) withObject:self afterDelay:1];
//show scrollview
NSLog(@"show sv\n\n\n\n");
[self performSelector:@selector(showScroll) withObject:self afterDelay:1];
}