3

第一次啓動我的應用程序後,我想向用戶展示一個小教程,以解釋我的應用程序的功能。所有UI前面的透明UIImageView

所以我需要設置一個帶有箭頭和標籤的透明UIImageView,其中主要UI(更具體地說,tabbarcontroler中的navigationviewcontroller中的tableviewcontroller)在教程圖像後面仍然可見。

而且,由於教程由多個圖像組成,因此我想添加一個輕擊手勢以切換到另一個圖像。

我試着將一個UIImageView添加到我的tabbarcontroller中,併爲此添加了一個gesturerecogniser,但它對我的水龍頭沒有反應,它只是起作用,就像沒有ImageView - 選擇了表中的魚子一樣,推按鈕。

-(void)nextTap:(UIGestureRecognizer*)nextTap 
{ 
    //Show another image 
} 
-(void)showTutorial 
{ 
    NSLog(@"Show tutorial"); 
    UIImageView *tutorialImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BG"]]; 
    [self.navigationController.tabBarController.view addSubview:tutorialImage]; 
    UITapGestureRecognizer *nextTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nextTap:)]; 
    [tutorialImage addGestureRecognizer:nextTap]; 
} 

有人可以告訴我,我應該在哪裏添加我的視圖,而不是它的正常工作?

+1

是否需要用戶交互設置爲YES圖像視圖?這是默認的NO。 – jmstone617 2012-04-06 11:44:52

回答

1

你應該設置tutorialImage.userInteractionEnabled = YES 的UIImageView的userInteractionEnabled屬性的默認值是NO,它阻止的UIImageView接收任何觸摸事件,甚至手勢

+0

謝謝,正是我需要的) – 2012-04-06 17:22:50

2

剛剛嘗試添加標籤bar.This可能工作fine.I不明白你的主要需求後添加圖像視圖到主屏幕,

3

與其他的UIWindow做到這一點!

像這樣:

-(void)showTutorial 
{ 
    NSLog(@"Show tutorial"); 


    CGRect screenBounds = [UIScreen mainScreen].bounds; 
    UIWindow *anotherWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenBounds.size.width, screenBounds.size.height)]; 
    anotherWindow.windowLevel = UIWindowLevelAlert+1; 
    [anotherWindow makeKeyAndVisible]; 

    // make the background of the new window black alpha 0.5 
    anotherWindow.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5]; 

    // add a test-image (icon) 
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]]; 
    [anotherWindow addSubview:image]; 

    UIImageView *tutorialImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BG"]]; 
    [anotherWindow addSubview:tutorialImage]; 
    UITapGestureRecognizer *nextTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nextTap:)]; 
    [tutorialImage addGestureRecognizer:nextTap]; 
} 

EDITED!現在它應該也適用於你的情況。

+0

不知道爲什麼,但你的代碼片段不適合我 - 但我覺得,應該這樣)方法被調用,但沒有任何明顯的變化) – 2012-04-06 10:11:37

+0

你給我帶來希望一次又一次,但沒有任何工作無論如何) – 2012-04-06 11:25:55

+0

我不希望在appdelegate中這樣做,對吧?在我的視圖控制器中,對吧? – 2012-04-06 11:31:26