3

我做了一个游戏,开始显示活动指示器和活动指示器底部显示带有文本的 UiLable 是:- 2秒后准备好文本是:-设置和 2 秒后文本是:-开始。

现在我使用 3 个不同的警报来显示这个。

我可以只用一个警报来做到这一点吗

4

3 回答 3

0

我想你想要这种类型的警报在此处输入图像描述

这样做试试这个

在 .h 文件中

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
    IBOutlet UILabel *Lable;
    NSTimer *Timer1;
    NSTimer *Timer2;
    UIActivityIndicatorView *Process;
    UIAlertView *Game;
}
-(IBAction)start:(id)sender;

@end

在 .M 文件中

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
int i;

- (void)viewDidLoad
{
    [super viewDidLoad];
}
-(IBAction)start:(id)sender
{
    i=0;
    Game=[[UIAlertView alloc]initWithTitle:@"Please Wait" message:@"\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    Process=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    Process.frame=CGRectMake(129, 50, 30, 27);
    [Process startAnimating];


    Lable=[[UILabel alloc]initWithFrame:CGRectMake(102, 80, 80, 30)];
    Lable.text=@"Ready";
    Lable.backgroundColor=[UIColor clearColor];
    Lable.textColor=[UIColor whiteColor];
    Lable.textAlignment= UITextAlignmentCenter;
    [Game addSubview:Lable];
    [Game addSubview:Process];
    [Game show];
    Timer1 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(Change) userInfo:nil repeats:NO];
}
-(void)Change{
    Timer2 = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(Change) userInfo:nil repeats:NO];
    if (i==0)
        Lable.text=@"Set";
    else
        Lable.text=@"Go";

    i++;
    if (i==3) {
        [Timer2 invalidate];
        Timer2=nil; 
        [Process stopAnimating];
        [Game dismissWithClickedButtonIndex:0 animated:YES];

    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
于 2013-03-26T11:11:32.713 回答
0

下载 SVProgressHUD。这将在 2-3 行代码中为您解决。它工作得很好(它可能没有可更改的消息。如果是这样,请尝试下面的 MBProgressHUD)

https://github.com/samvermette/SVProgressHUD

还有一个 MBprogressHUD 可以让你在进程的中途更改消息,但我发现它会在应用程序中引起一些小问题。

https://github.com/jdg/MBProgressHUD

于 2013-03-26T13:15:46.040 回答
0
UIAlertView *processview;
UILabel *lbl;
NSTimer *enableTimer;
int count;

- (void)enableTimerFired:(NSTimer *)timer
{
    switch (count)
    {
        case 1:
            [lbl setText:@"Ready"];
        break;

        case 2:
            [lbl setText:@"Set"];
        break;

        case 3:
            [lbl setText:@"Go"];
        break;

        case 4:
            [enableTimer invalidate];
            enableTimer = nil;
            [processview dismissWithClickedButtonIndex:-1 animated:YES];
        break;

        default:
        break;

    }
    count++;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    processview =  [[UIAlertView alloc] initWithTitle:@"\n" message:@"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ;

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 90, 30)];
    [lbl setText:@"Ready"];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setTextColor:[UIColor whiteColor]];
    [lbl setTextAlignment:NSTextAlignmentCenter];
    [processview addSubview:lbl];

    UIActivityIndicatorView *largeActivity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [largeActivity setFrame:CGRectMake(120, 75, 50, 50)];
    [largeActivity startAnimating];

    [processview addSubview:largeActivity];
    [processview show];

    enableTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(enableTimerFired:) userInfo:nil repeats:YES] retain];
    count = 1;
}
于 2013-03-26T10:12:14.583 回答