【问题标题】:Transparent UIImageView in front of all the UI透明 UIImageView 在所有 UI 前面
【发布时间】:2012-04-06 09:52:02
【问题描述】:

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

所以我需要设置一个带有一些箭头和标签的透明 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];
}

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

【问题讨论】:

  • 您需要将图像视图的 userInteraction 设置为 YES 吗?默认为 NO。

标签: objective-c ios uitableview uinavigationcontroller uiimageview


【解决方案1】:

用另一个 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];
}

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

【讨论】:

  • 不知道为什么,但你的 sn-p 对我不起作用——但我觉得应该这样)调用了方法,但没有任何明显的变化)
  • 我不应该在 appdelegate 中这样做,对吗?在我的视图控制器中,是吗?
  • 测试。有用。我在应用程序委托中完成了代码。但是你可以从任何地方运行它。您至少应该在 UI 的其余部分看到 50% 的 alpha 黑色视图(窗口)。
  • 不知道为什么,但这对我不起作用)但是启用 UserInteraction 解决了我的问题
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • 谢谢,正是我需要的)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多