2013-03-26 2 views
3

я сделать игру, начать отображение индикатора активности и индикатор активности нижней дисплей UiLable с текстом является: - Готовый после 2 сек Lable текст: - Set И после 2 Сективный текст: - Перейти.дисплей предупреждение активность Индикатор и Lable (сменная)

сейчас я использую 3 разных оповещения, чтобы отобразить это.

Могу ли я сделать это только одно предупреждение

ответ

0

я думаю, что вы хотите этот тип оповещения enter image description here

делать это Try This

ПО .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)]; 
    [email protected]"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) 
     [email protected]"Set"; 
    else 
     [email protected]"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 
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; 
} 
0

Скачать SVProgressHUD. Это позаботится об этом для вас в 2-3 строках кода. Она работает очень хорошо (она не может иметь изменяемое сообщение. Если это так, попробуйте MBProgressHUD ниже)

https://github.com/samvermette/SVProgressHUD

Существует также MBprogressHUD, который может позволить вам изменить сообщения на полпути через процесс, но я обнаружил, что это вызывает некоторые незначительные проблемы в приложении.

https://github.com/jdg/MBProgressHUD

Смежные вопросы