Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent UIImageView in front of all the UI

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?

like image 992
Nikita Pestrov Avatar asked Nov 24 '25 03:11

Nikita Pestrov


2 Answers

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.

like image 96
Jonas Schnelli Avatar answered Nov 26 '25 17:11

Jonas Schnelli


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,

like image 45
Rama Rao Avatar answered Nov 26 '25 16:11

Rama Rao