Возможность прикоснуться к фону индикатора активности - PullRequest
1 голос
/ 30 октября 2011

В моем приложении для iphone индикатор активности отображается во время вызова веб-службы. Моя проблема в том, что я могу касаться представления, на котором отображается индикатор активности. В моем представлении есть текстовые поля и кнопки, и я могу вводить значения в текстовые поля, а также изменять состояния кнопок, пока индикатор активности все еще включен , Кто-нибудь сталкивался с подобной ситуацией? Кто-нибудь знает решение этой проблемы? Все полезные предложения приветствуются. Вот мой класс индикатора активности.

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 Ответ

4 голосов
/ 30 октября 2011

Вы добавляете свой индикатор активности в середину другого представления, да?

Если это так, вы можете сделать это с помощью 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

Надеюсь, это поможет!

...