2012-09-17 26 views
1

所以我有一個時間延遲操作,以便當一個一個按下按鈕,它會顯示(5秒)如何使UIButton以預定的時間間隔出現?

-(IBAction)start{ 

Desc.text = @"Text appears"; 
[self performSelector:@selector(delay) withObject:nil afterDelay:5.0]; 

} 

-(void)delay{ 

Desc2.text = @"Text to appear in 5 seconds"; 
[self performSelector:@selector(delayA) withObject:nil afterDelay:5.0]; 

} 

至於下一行代碼,我試圖在設定的時間圖後的標籤使是的,而不是一個標籤會在預定的時間間隔後出現,我試圖讓一個按鈕在5秒內出現。

任何人都可以幫忙嗎?

+1

你想要第一個按鈕是隱藏然後5秒後按鈕就會顯示,對嗎? –

+0

使用'[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeatats:]' – Scar

+0

你想要什麼?我和@ParasJoshi有同樣的問題 – TheTiger

回答

0

首先你的UIButton是必須隱藏例如你的按鈕名稱爲BTN1然後viewDidLoad:方法編寫代碼

- (void)viewDidLoad 
{ 

    btn1.hidden = YES; 

} 

-(IBAction)start{ 
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 
              target:self 
              selector:@selector(targetMethod:) 
              userInfo:nil 
              repeats:YES]; 
} 
-(IBAction)targetMethod:(id)sender{ 
     btn1.hidden = NO; 
} 

使用此代碼拖放您XIB按鈕,有的名稱是BTN1或爲u希望...

我希望這個答案對你有幫助..

:)

0
UIButton *btn = [UIButton alloc] initWithFrame:[Desc2 frame]]; 

[btn setTitle: [Desc2 text] forState:UIControlStateNormal]; 

[self.view addSubview:btn]; 

這段代碼的代碼創建一個UIButton其中DESC2 UILabel是和設置按鈕的什麼DESC2有標題。

你可以把它放在delayA方法裏面。

0
-(void)delayA{ 

UIButton *button = [[UIButton alloc] init]; 
button.frame = CGRectMake(x, y, width, height); //add the parameters 
[self.view addSubview:button]; 
} 

希望它有幫助。快樂編碼:)

0

您可以使用以下方法:

[NSTimer scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:] 
0

試試這個,

NSTimer *aTimer = [NSTimer timerWithTimeInterval:(5.0) target:self selector:@selector(timerFired:) userInfo:nil repeats:YES]; 
    NSRunLoop *runner = [NSRunLoop currentRunLoop]; 
    [runner addTimer:aTimer forMode: NSDefaultRunLoopMode]; 

,並設置要在

-(void)timerFired:(NSTimer *) theTimer 
{ 
} 
0

要執行的操作如果您只嘗試顯示和隱藏按鈕,使用alpha屬性。

// show button 
[self.yourButton setAlpha: 1] 

// hide button 
[self.yourButton setAlpha: 0]; 
相關問題