私のiPhoneアプリケーションでは、Webサービスコール時にアクティビティインジケータが表示されます。私の問題は、アクティビティインジケータが表示されているビューに触れることができることです。私のビューにはテキストフィールドとボタンがあり、アクティビティインジケータがまだオンの状態でテキストフィールドに値を入力したりボタンの状態を変更することができます。誰も似たような状況に直面したことがありますか?誰もがこの問題の解決策を知っていますか?すべての有益な提案が歓迎されます。 私のアクティビティインジケータクラスは次のとおりです。アクティビティインジケータの背景に触れることができます
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];
}
これはうまくいきました。ありがとうございます。でも問題は残っています。私のアプリケーションでは、オーディオファイルを書き出しているときにそのアクティビティインジケータも使用しています。ここでも同じ問題が発生します。 – Siddharth
同じソリューションもそこで動作するはずです。アクティビティインジケータを追加したビューが何であれ、 'userInteractionEnabled'をNOに設定すると、アクティビティが完了するまでタッチを無効にする必要があります。 –
エクスポートのケースで、私は[ActivityProgressViewController close]が呼び出されたことに気付きました。しかし、その後もアクティビティインジケータが存在し、バックグラウンドビューのUI要素に触れることができます。私は、これは非同期のエクスポートと関係があると思います。上記のエクスポートコードを参照用に追加しました。 – Siddharth