无话,上代码:
//WaitingDialog.h
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
@interface WaitingDialog : CDVPlugin {
}
// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
//- (void) show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
- (void) show:(CDVInvokedUrlCommand*)command;
- (void) hide:(CDVInvokedUrlCommand*)command;
@end
//WaitingDialog.m
#import "WaitingDialog.h"
@interfaceWaitingDialog () {
UIAlertView *waitingDialog;
}
@property (nonatomic, retain) UIAlertView *waitingDialog;
-(void)showWaitingDialogWithText:(NSString*)text;
-(void)hideWaitingDialog;
@end
@implementation WaitingDialog
@synthesize waitingDialog = _waitingDialog;
-(UIAlertView *)waitingDialog {
if (!_waitingDialog || _waitingDialog == nil) {
_waitingDialog = [[[UIAlertViewalloc] initWithTitle:@""message:nildelegate:selfcancelButtonTitle:nilotherButtonTitles: nil] autorelease];
}
return_waitingDialog;
}
// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
//- (void) show:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
// NSString *text = @"Please wait...";
// @try {
// text = [options valueForKey:@"text"];
// }
// @catch (NSException *exception) {
// NSLog(@"Cannot read text argument")
// }
//
// [self showWaitingDialogWithText:text];
//}
// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
- (void) show:(CDVInvokedUrlCommand*)command {
NSString *text = @"请稍候...";
@try {
text = [command.arguments objectAtIndex:0];
}
@catch (NSException *exception) {
NSLog(@"读取文本参数失败");
}
[selfshowWaitingDialogWithText:text];
}
// UNCOMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
//- (void) hide:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
// [self hideWaitingDialog];
//}
// COMMENT THIS METHOD if you want to use the plugin with versions of cordova < 2.2.0
- (void) hide:(CDVInvokedUrlCommand*)command {
[selfhideWaitingDialog];
}
#pragma mark - PRIVATE METHODS
-(void)showWaitingDialogWithText:(NSString *)text {
[self.waitingDialog setTitle:text];
[self.waitingDialogshow];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorViewalloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(self.waitingDialog.bounds.size.width / 2, self.waitingDialog.bounds.size.height - 50);
[indicator startAnimating];
[self.waitingDialog addSubview:indicator];
[indicator release];
//给UIAlertView增加触屏响应功能
UITapGestureRecognizer *tapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)];
[self.waitingDialogaddGestureRecognizer:tapOne];
[tapOne release];
}
//UIAlertView触屏事件响应函数,用以关闭进度提示框
- (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender
{
// NSLog(@"进入触摸事件...");
[selfhideWaitingDialog];
}
-(void)hideWaitingDialog {
if (_waitingDialog) {
[self.waitingDialogdismissWithClickedButtonIndex:0animated:YES];
_waitingDialog = nil;
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[selfhideWaitingDialog];
}
@end