Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create click-through overlay instruction view

A really simple question here. How do you create a view like this? enter image description here

It has to overlay the first time user runs this part of the app and be removed forever once the user taps on it. I understand it should be a UIImageView, but how do you make it active and then remove it from the view forever?

like image 690
Sergey Grischyov Avatar asked Sep 05 '12 21:09

Sergey Grischyov


3 Answers

You can add your subview just after your app launch in the didFinishLaunchingWithOptions method of your app delegate by using the addSubView method of the UIView class. Here are some code snippets of how you could proceed:

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    UIImageView *imageView = [[UIImageView alloc] 
    initWithImage:[UIImage imageNamed:@"yourimage.png"]];
    [self.window addSubview:imageView];

     UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
     recognizer.delegate = self;
    [imageView addGestureRecognizer:recognizer];
    imageView.userInteractionEnabled =  YES;
    self.imageView = imageView;
}

- (void) handleTap:(UITapGestureRecognizer *)recognize
{
     [self.imageView removeFromSuperView];
}

Note that you will need a property to reference your imageView in the handleTap method.

like image 200
tiguero Avatar answered Oct 23 '22 18:10

tiguero


UIView has all the methods you need, e.g.

  • Call [myView addSubview:imgView] to add the image view to the current view (myView)
  • Call [imgView removeFromSuperview] when finish (i.e. in respond to tap or after a timer)

Make sure userInteractionEnabled property of imgView to NO so that touches are passed to myView.

like image 22
Buu Nguyen Avatar answered Oct 23 '22 19:10

Buu Nguyen


My thoughts would be set an NSUserDefault variable and check it on applicationDidFinishLaunchingWithOptions or somewhere else in your app that makes sense. You could just push a separate view when your variable is true vs. false.

like image 1
Michael Avatar answered Oct 23 '22 18:10

Michael