Skip to content

Instantly share code, notes, and snippets.

@lexrus
Created May 11, 2016 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexrus/db892e33216d1cb1e09ef9364162a49e to your computer and use it in GitHub Desktop.
Save lexrus/db892e33216d1cb1e09ef9364162a49e to your computer and use it in GitHub Desktop.
iOS task list hint
//
// BackgroundHint.m
// Zus
//
// Created by Lex on 4/13/16.
// Copyright © 2016 lex.sh. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface BackgroundHint : NSObject
@end
@implementation BackgroundHint
static const UInt8 kBackgroundHintTag = 45;
+ (void) load {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(showHint)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hideHint)
name:UIApplicationDidBecomeActiveNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(hideHint)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}
+ (UIImageView *) hintImageView {
UIImageView *view = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
view.image = [UIImage imageNamed:@"background_hint"];
view.tag = kBackgroundHintTag;
[view setContentMode:UIViewContentModeScaleAspectFill];
return view;
}
+ (void) showHint {
UIView *view = [[UIApplication sharedApplication] keyWindow].subviews.lastObject;
[view addSubview: [self hintImageView]];
}
+ (void) hideHint {
UIView *view = [[UIApplication sharedApplication] keyWindow].subviews.lastObject;
UIView *hintView = [view viewWithTag:kBackgroundHintTag];
[hintView removeFromSuperview];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment