簡體   English   中英

全屏查看活動指示器

[英]Viewing Activity Indicator in fullscreen

我試圖以全屏顯示活動指示器,以便用戶無法按屏幕上的任何按鈕,直到在警報查看過程中關閉活動指示器為止。 我已經叫[activityView startAnimating]但是我可以按下后面的按鈕。 有辦法防止這種情況嗎?

從現在開始謝謝。

您可以將MBProgressHUD用於此類加載指示符 如果您想進一步定制它,這是一個很好的MIT許可類,可以很好地擴展。

我建議最好的方法是在屏幕上顯示帶有活動指示器的alertView。 您可以為此使用以下代碼:

聲明UIAlertView屬性,例如:

@property (nonatomic, strong) UIAlertView *sendAlert;

self.sendAlert = [[UIAlertView alloc] initWithTitle:@"Loading" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act setFrame:CGRectMake(115, 60, 50, 50)];
[act startAnimating];
[sendAlert addSubview:act];     
act = nil;
[sendAlert show];

當您想刪除警報時,可以使用:

[sendAlert dismissWithClickedButtonIndex:0 animated:YES];   
sendAlert = nil;

另一種選擇是,您可以將活動指示器添加到視圖本身,並將backbutton的userInteraction設置為false。 完成任務后,將其設置為True。 但這不是一個好方法。

你可以試試這個

 UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:@"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];

[indicator release];

並在要刪除警報的位置添加此行

 [alert dismissWithClickedButtonIndex:0 animated:YES];

嘿,您的此要求使用以下代碼,您可以在每次使用視圖時訪問該代碼。

將此波紋管代碼和對象添加到AppDelegate.h文件中,例如波紋管。

UIView *activityView;
UIView *loadingView;
UILabel *lblLoad;

並將下面的代碼粘貼到AppDelegate.m文件中

#pragma mark - Loading View
-(void) showLoadingView {
    //NSLog(@"show loading view called");
    if (loadingView == nil) 
    {
        loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
        loadingView.opaque = NO;
        loadingView.backgroundColor = [UIColor darkGrayColor];
        loadingView.alpha = 0.5;

        UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
        subloadview.backgroundColor=[UIColor blackColor];
        subloadview.opaque=NO;
        subloadview.alpha=0.8;

        subloadview.layer.masksToBounds = YES;
        subloadview.layer.cornerRadius = 6.0;

        lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
        lblLoad.text=@"LoadingView";
        lblLoad.backgroundColor=[UIColor clearColor];
        lblLoad.textColor=[UIColor whiteColor];
        [subloadview addSubview:lblLoad];

        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
        [spinningWheel startAnimating];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [subloadview addSubview:spinningWheel];
        [loadingView addSubview:subloadview];
        [spinningWheel release];
    }       
    [self.window addSubview:loadingView];

    //[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}


-(void) hideLoadingView {
    if (loadingView) {
        [loadingView removeFromSuperview];
        [loadingView release];
        loadingView = nil;
    }

}

並在需要的任何類中調用此方法,就像下面這樣。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];

活動指示器啟動時,在當前視圖上方添加一個UIView:

UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.navigationController.view addSubview:overlayView];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM