Elias Rahme
Elias Rahme

Reputation: 2227

Showing UIImageView on startup after a delay with close button

I want to show a UIImageView after 3 seconds from the view did load. This image view is kind of a static Ad, a static image loaded that will show up when the application starts as mentioned. This ismageView should have a close button on it so the user can close it just like the typical ad behavior. It's my first time dealing with this kind of situations so please help me out i'm totally lost.

Till now i got to animate a view containing an image view with fade in and out animations, which is perfect..but now haw can i add a close button to it, to make her dismiss only when that button is pressed? this is my code

UIImageView *wnn = [[UIImageView alloc]init];
wnn.frame = CGRectMake(100, 100, 300, 300);
[wnn setImage:[UIImage imageNamed:@"menu-icon.png"]];
UIView *jn = [[UIView alloc]init];
[jn addSubview:wnn];
[self.navigationController.view addSubview: jn];
[jn setAlpha:0.f];

[UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseIn animations:^{
    [jn setAlpha:1.f];
} completion:^(BOOL finished) {
    [UIView animateWithDuration:2.f delay:0.f options:UIViewAnimationOptionCurveEaseInOut animations:^{
        [jn setAlpha:0.f];
    } completion:nil];
}];

Upvotes: 0

Views: 229

Answers (1)

A J
A J

Reputation: 605

You can follow below steps:

  1. Open Storyboard file with your viewcontroller.
  2. Place UIView from library to your main view of viewcontroller.
  3. Place your image and close button on new UIview placed.
  4. Now set IBOutlet for this uiview.
  5. Make hide/show this view instead of image and close button in your method.

Upvotes: 1

Related Questions