2012-09-21 75 views
0

我有2 ViewControllers和我創建一個UIImageView顯示像iPhone上的閃屏。我把它寫在TestAppDelegate.m觸摸ImageView到另一個ViewController

====================

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 

splashScreen.image = [UIImage imageNamed:@"Default.png"]; 

[self.window addSubview:splashScreen]; 

sleep(6); 

[splashScreen removeFromSuperview]; 

============= =======

我的問題是,

如果我談談這個imageview我會去第二ViewController

其他時間睡眠後,自動到第1 ViewController

那麼,有可能做到這一點?

+0

你的圖像是'UIButton'如何時,將叫什麼名字? –

回答

2

這樣做:

在appDelegate.h文件添加UIGestureRecognizerDelegate。

@interface AppDelegate : UIResponder <UIApplicationDelegate,UIGestureRecognizerDelegate> 

現在

splashScreen = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
splashScreen.userInteractionEnabled = YES; 
splashScreen.image = [UIImage imageNamed:@"Default.png"]; 
UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; 
tapRecognizer.numberOfTapsRequired = 1; 
tapRecognizer.numberOfTouchesRequired = 1; 
tapRecognizer.delegate = self; 
[splashScreen addGestureRecognizer:tapRecognizer]; 
[tapRecognizer release]; 

[self.window addSubview:splashScreen]; 

sleep(6); 
[splashScreen removeFromSuperview]; 
//add ViewController1 here 
ViewController1 *objViewController1 = [[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil]; 
[self.window addSubview:objViewController1.view]; 

現在處理程序的啓動畫面上點擊

- (void)handleTap:(UITapGestureRecognizer*)recognizer 
{ 
    // Do Your thing. 
    if (recognizer.state == UIGestureRecognizerStateEnded) 
    { 
    [splashScreen removeFromSuperview]; //edited here 
    ViewController2 *objViewController2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil]; 
    [self.window addSubview:objViewController2.view]; 
    } 
} 
+0

FirstViewController工作但SecondViewController不起作用。我不知道爲什麼。 – Sovannarith

+0

它不叫方法handTap,我也記錄它。 – Sovannarith

+0

tapRecognizer.numberOfTapsRequired = 1; tapRecognizer.numberOfTouchesRequired = 1; tapRecognizer.delegate = self;在回答 –

0

是的。這是可能的。在AppDelegate保持。

在定時器寫入代碼的選擇器中推送到第1個視圖控制器。

並將Touch Recognizer放在imageview和觸摸事件編寫代碼上以推送到第二個視圖控制器。

+0

你有沒有給我一個示例代碼? – Sovannarith

相關問題