Header file --------------------------------------------------
//
// WaitView.h
// UIActivityIndicatorView
//
// Created by Lin, Justin on 2011/3/22.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import
@interface WaitView : NSObject {
UIActivityIndicatorView *activityIndicator;
}
-(void) endWait;
- (void) beginWait;
@end
Source file --------------------------------------------------
//
// WaitView.m
// UIActivityIndicatorView
//
// Created by Lin, Justin on 2011/3/22.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "WaitView.h"
@interface WaitView(PrivateMethods)
- (UIView *) mainWindow;
- (void) startWaitAnimation;
- (void) stopWaitAnimation;
@end
@implementation WaitView
- (UIView *) mainWindow {
return [[[UIApplication sharedApplication] windows] objectAtIndex:0];
}
- (void) startWaitAnimation {
if (activityIndicator != nil) {
return;
}
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityIndicator setFrame:CGRectMake(135, 125, 24, 24)];
[activityIndicator setHidesWhenStopped:YES];
[[self mainWindow] addSubview:activityIndicator];
[activityIndicator startAnimating];
}
- (void) stopWaitAnimation {
if (activityIndicator == nil) {
return;
}
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}
-(void) endWait {
// stop thread
[NSThread detachNewThreadSelector: @selector(stopWaitAnimation) toTarget:self withObject:nil];
}
- (void) beginWait {
// start thread
[NSThread detachNewThreadSelector: @selector(startWaitAnimation) toTarget:self withObject:nil];
}
@end
沒有留言:
張貼留言