能够触及活动指标的背景

时间:2011-10-30 09:21:32

标签: iphone objective-c ios uiactivityindicatorview activity-indicator

在我的iphone应用程序中,在webservice调用时会显示一个活动指示器。我的问题是,我能够触摸显示活动指示器的视图。我的视图有文本字段和按钮,我能够在文本字段中输入值,并在活动指示器仍在其上时更改按钮状态。有人遇到过类似的情况吗?有人知道这个问题的解决方案吗?欢迎所有有用的建议。 这是我的活动指标类。

ActivityProgressViewController.h

#import <UIKit/UIKit.h>

@interface ActivityProgressViewController : UIViewController {
    IBOutlet UIActivityIndicatorView *_activityIndicator;
    IBOutlet UILabel *_labelMessage;
    NSString *_messageToShow;
}

@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
@property (nonatomic, retain) IBOutlet UILabel *labelMessage;

+ (ActivityProgressViewController*) createInstance;

- (void)show;
- (void)showWithMessage:(NSString*)message;
- (void)close;


+ (void)show;
+ (void)close;

@end

ActivityProgressViewController.m

#import "ActivityProgressViewController.h"

#define kACTIVITY_INDICATOR_NIB @"ActivityProgressViewController"

@implementation ActivityProgressViewController

@synthesize activityIndicator = _activityIndicator;
@synthesize labelMessage = _labelMessage;


static ActivityProgressViewController *_viewController;


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad {
    if (_messageToShow) _labelMessage.text = _messageToShow;
}

- (void)dealloc {
    [_labelMessage release];
    [_messageToShow release];
    [_activityIndicator release];
    [super dealloc];
}

+ (ActivityProgressViewController*) createInstance {
    _viewController = [[ActivityProgressViewController alloc] initWithNibName:kACTIVITY_INDICATOR_NIB bundle:nil];
    return _viewController;
}

- (void)show
{
    [_activityIndicator startAnimating];

    UIWindow *window = [[[UIApplication sharedApplication] windows]objectAtIndex:0];
    NSLog(@"[[UIApplication sharedApplication] windows]===%@",[[UIApplication sharedApplication] windows]);

    self.view.frame = CGRectMake(window.bounds.origin.x, window.bounds.origin.y, window.bounds.size.width, window.bounds.size.height);

    [window addSubview:self.view];

}



- (void)showWithMessage:(NSString*)message {
    _messageToShow = message;
    [self show];
}

- (void)close
{
    [self.view removeFromSuperview];

}

+ (void)show {
    if (!_viewController) {
        _viewController = [ActivityProgressViewController createInstance];
    }
    [_viewController show];
}

+ (void)close {
    if (_viewController) {
        [_viewController close];
    }
}

@end

以下是我从我所需的课程致电的方式。

 [ActivityProgressViewController show];

 [ActivityProgressViewController close];

我还在导出音频时调用活动指示器。 这是我用于导出的代码

    -(void)exportAudioFile:(AVComposition*)combinedComposition
{

[ActivityProgressViewController show];

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:combinedComposition
                                                                           presetName:AVAssetExportPresetPassthrough];

    NSArray *presets =[AVAssetExportSession exportPresetsCompatibleWithAsset:combinedComposition];

    NSLog(@"presets======%@",presets);
    NSLog (@"can export: %@", exportSession.supportedFileTypes);
    NSArray *dirs = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [dirs objectAtIndex:0];
    exportPath = [documentsDirectoryPath stringByAppendingPathComponent:@"CombinedNew.m4a"];
    [[NSFileManager defaultManager] removeItemAtPath:exportPath error:nil];
    exportURL = [NSURL fileURLWithPath:exportPath];
    exportSession.outputURL = exportURL;
    exportSession.outputFileType = @"com.apple.m4a-audio";
    exportSession.shouldOptimizeForNetworkUse = YES;
    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        NSLog (@"i is in your block, exportin. status is %d",
               exportSession.status);
        switch (exportSession.status) 
        {
            case AVAssetExportSessionStatusFailed: 
            {

                break;
            }
            case AVAssetExportSessionStatusCompleted: 
            {

                exportSuccess = YES;
                if (recorderFilePath) 
                {
                    NSError *finalurlError;
                    [[NSFileManager defaultManager]removeItemAtPath:recorderFilePath  error:&finalurlError];
                    finalurlError = nil;
                    [[NSFileManager defaultManager]copyItemAtPath:[exportURL path] toPath:recorderFilePath error:&finalurlError];
                    NSLog(@"finalurlError 2-----%@",finalurlError);
                }
                [ActivityProgressViewController close];
                fileUrl = [NSURL fileURLWithPath:recorderFilePath];  
                [self updatePlayerForUrl:fileUrl];
                break;
            }
            case AVAssetExportSessionStatusUnknown: 
            {   

                break;
            }
            case AVAssetExportSessionStatusExporting: 
            { 

                break;
            }
            case AVAssetExportSessionStatusCancelled: 
            { 

                break;
            }
            case AVAssetExportSessionStatusWaiting: 
            { 

                break;
            }
            default: 
            { 
                NSLog (@"didn't get export status");
                break;
            }

        };
    }];

    [exportSession release];
}

1 个答案:

答案 0 :(得分:4)

您是将活动指示符添加到另一个视图的中间,是吗?

如果是这样,您可以使用show方法执行此操作:

self.superview.userInteractionEnabled = NO;

并使用close方法:

self.superview.userInteractionEnabled = YES;

您可以在此处找到有关UIView的userInteractionEnabled属性的信息:http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/userInteractionEnabled

希望这有帮助!