1. 在xxxViewController.h的@interface xxxViewController...中宣告
UIActivityIndicatorView * activityIndicator;
並加上如下的程式碼:
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView * activityIndicator;
-(void)spinActivityIndicatorBegin;
-(void)spinActivityIndicatorEnd;
2. 使用Interface Builder 擺一個UIActivityIndicatorView在你想要放置的位置上,並連接到上面這個 activityIndicator;設置屬性為 hidden when stopped.
3. 在xxxViewController.m實作spinActivityIndicatorBegin與spinActivityIndicatorEnd如下:
- (void) spinActivityIndicatorBegin {
[activityIndicator startAnimating];
}
- (void) spinActivityIndicatorEnd {
[activityIndicator stopAnimating];
}
4. 在xxxViewController.m耗時運算的前後作如下的呼叫:
[NSThread detachNewThreadSelector: @selector(spinActivityIndicatorBegin) toTarget:self withObject:nil];
//此處為耗時運算
[NSThread detachNewThreadSelector: @selector(spinActivityIndicatorEnd) toTarget:self withObject:nil];
完成後執行程式應該就可以看到小菊花在你設定的位置轉阿轉的囉!
No comments:
Post a Comment