Transparent UIImageView in front of all the UI

倾然丶 夕夏残阳落幕 提交于 2019-12-12 16:27:52

问题


After the first launch of my app i want to show the user a little tutorial, to explain the functionality of my app.

So i need to set a transpalent UIImageView with some arrow and labels, where the main UI(more specificly,tableviewcontroller in navigationviewcontroller in a tabbarcontroler) is stil visible behind the tutorial image.

And,because tutorial consists of several images,I want to add a tap gesture that will switch to another image.

I tried just to add an UIImageView to my tabbarcontroller,and andd a gesturerecogniser to that, but it doesn't react to my tap's,it just works,like if there were no ImageView - selects's the roe in table,pushes the buttons.

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

Can anybody tell me, where should i add my view than,for it to work properly?


回答1:


you should set tutorialImage.userInteractionEnabled = YES The default value of UIImageView's userInteractionEnabled property is NO, it prevent UIImageView receive any touch event even gestures




回答2:


do it with another UIWindow!

Like this:

-(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! now it should work also in your case.




回答3:


Just try to add the image view to main screen after adding tab bar.This may work fine.I didn't understand the main requirement of your's,



来源:https://stackoverflow.com/questions/10041854/transparent-uiimageview-in-front-of-all-the-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!