Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.