Phonegap之WaitingDialog For iOS

无话,上代码:

 

//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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值