3

在我的应用程序首次启动后,我想向用户展示一个小教程,以解释我的应用程序的功能。

所以我需要设置一个带有一些箭头和标签的透明 UIImageView,其中主 UI(更具体地说,tabbarcontroler 中的 navigationviewcontroller 中的 tableviewcontroller)在教程图像后面仍然可见。

而且,由于教程由多张图片组成,我想添加一个点击手势来切换到另一张图片。

我试图在我的标签栏控制器中添加一个 UIImageView,并添加一个手势识别器,但它不会对我的点击做出反应,它只是工作,就像没有 ImageView 一样 - 选择表中的 roe,按下按钮。

   -(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];
}

谁能告诉我,我应该在哪里添加我的视图,以便它正常工作?

4

3 回答 3

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];
}

已编辑!现在它也应该适用于您的情况。

于 2012-04-06T10:01:32.087 回答
2

在添加标签栏后尝试将图像视图添加到主屏幕。这可能工作正常。我不明白你的主要要求,

于 2012-04-06T10:00:15.693 回答
1

你应该设置 tutorialImage.userInteractionEnabled = YES UIImageView 的 userInteractionEnabled 属性的默认值为 NO,它会阻止 UIImageView 接收任何触摸事件甚至手势

于 2012-04-06T14:42:30.677 回答