Skip to content

Instantly share code, notes, and snippets.

@ShaharHD
Created June 15, 2014 14:30
Show Gist options
  • Save ShaharHD/70e8c91d111dfd24d9b5 to your computer and use it in GitHub Desktop.
Save ShaharHD/70e8c91d111dfd24d9b5 to your computer and use it in GitHub Desktop.
splashView
//
// splashView.h
// version 1.1
//
// Created by Shannon Appelcline on 5/22/09.
// Copyright 2009 Skotos Tech Inc.
//
// Licensed Under Creative Commons Attribution 3.0:
// http://creativecommons.org/licenses/by/3.0/
// You may freely use this class, provided that you maintain these attribute comments
//
// Visit our iPhone blog: http://iphoneinaction.manning.com
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD ( [[[UIDevice currentDevice ] model] isEqualToString:@"iPod touch"] )
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )
@protocol splashViewDelegate <NSObject>
@optional
- (void)splashIsDone;
@end
typedef enum {
SplashViewAnimationNone,
SplashViewAnimationSlideLeft,
SplashViewAnimationFade,
} SplashViewAnimation;
@interface splashView : UIView{
UIImageView *splashImage;
}
@property (retain) id<splashViewDelegate> delegate;
@property (retain) UIImage *image;
@property NSTimeInterval delay;
@property BOOL touchAllowed;
@property SplashViewAnimation animation;
@property NSTimeInterval animationDelay;
@property BOOL isFinishing;
@property UIViewController *firstController;
- (id)initWithVC:(UIViewController *) myVC;
- (void)startSplash;
- (void)dismissSplash;
- (void)dismissSplashFinish;
@end
//
// splashView.m
// version 1.1
//
// Created by Shannon Appelcline on 5/22/09.
// Copyright 2009 Skotos Tech Inc.
//
// Licensed Under Creative Commons Attribution 3.0:
// http://creativecommons.org/licenses/by/3.0/
// You may freely use this class, provided that you maintain these attribute comments
//
// Visit our iPhone blog: http://iphoneinaction.manning.com
//
#import "splashView.h"
@implementation splashView
@synthesize delegate, image, delay, touchAllowed, animation, isFinishing, animationDelay;
- (id)initWithVC:(UIViewController *) myVC{
if ((self = [super initWithFrame:[[UIScreen mainScreen] bounds]])) {
// changed to bounds from application frame
self.delay = 2.5;
self.touchAllowed = YES;
self.animation = SplashViewAnimationFade;
self.animationDelay = .25;
self.isFinishing = NO;
self.firstController = myVC;
if(IS_IPHONE_5)
self.image = [UIImage imageNamed:@"Default-568h"];
else
self.image = [UIImage imageNamed:@"Default"];
}
return self;
}
- (void)startSplash {
[self.firstController.view addSubview:self];
splashImage = [[UIImageView alloc] initWithImage:self.image];
[self addSubview:splashImage];
[self performSelector:@selector(dismissSplash) withObject:self afterDelay:self.delay];
}
- (void)dismissSplash {
if (self.isFinishing || self.animation == SplashViewAnimationNone) {
[self dismissSplashFinish];
} else if (self.animation == SplashViewAnimationSlideLeft) {
CABasicAnimation *animSplash = [CABasicAnimation animationWithKeyPath:@"transform"];
animSplash.duration = self.animationDelay;
animSplash.removedOnCompletion = NO;
animSplash.fillMode = kCAFillModeForwards;
animSplash.toValue = [NSValue valueWithCATransform3D:
CATransform3DMakeAffineTransform
(CGAffineTransformMakeTranslation(-320, 0))];
animSplash.delegate = self;
[self.layer addAnimation:animSplash forKey:@"animateTransform"];
} else if (self.animation == SplashViewAnimationFade) {
CABasicAnimation *animSplash = [CABasicAnimation animationWithKeyPath:@"opacity"];
animSplash.duration = self.animationDelay;
animSplash.removedOnCompletion = NO;
animSplash.fillMode = kCAFillModeForwards;
animSplash.toValue = [NSNumber numberWithFloat:0];
animSplash.delegate = self;
[self.layer addAnimation:animSplash forKey:@"animateOpacity"];
}
self.isFinishing = YES;
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
[self dismissSplashFinish];
}
- (void)dismissSplashFinish {
if (splashImage) {
[splashImage removeFromSuperview];
[self removeFromSuperview];
}
if (self.delegate != NULL && [self.delegate respondsToSelector:@selector(splashIsDone)]) {
[delegate splashIsDone];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (self.touchAllowed) {
[self dismissSplash];
}
}
@end
@ShaharHD
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment