Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @implementation SplashView
- @synthesize timer;
- - (id)initWithSplashImage:(UIImage *)_splashImage sponsorsImages:(NSArray *)_images {
- if ((self = [super initWithNibName:nil bundle:nil])) {
- currentIndex = 0;
- splashView = [[UIImageView alloc] initWithImage:_splashImage];
- sponsorsImageViews = [[NSMutableArray alloc] initWithCapacity:[_images count]];
- for (UIImage *image in _images) {
- UIImageView *sponsorImageView = [[UIImageView alloc] initWithImage:image];
- [sponsorsImageViews addObject:sponsorImageView];
- [sponsorImageView release];
- }
- timer = nil;
- }
- return self;
- }
- - (void)loadView {
- UIView *v = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
- self.view = v;
- [v release];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self.view addSubview:splashView];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [self performSelector:@selector(runComingAnimation:) withObject:0 afterDelay:1];
- }
- - (void)runComingAnimation:(NSUInteger)index {
- if (index < [sponsorsImageViews count]) {
- currentIndex = index;
- UIImageView *sponsorImageView = [sponsorsImageViews objectAtIndex:index];
- CGRect viewRect = self.view.frame;
- CGRect rect = sponsorImageView.frame;
- rect.origin.x = viewRect.size.width;
- rect.origin.y = viewRect.size.height/2 - rect.size.height/2;
- sponsorImageView.frame = rect;
- [self.view addSubview:sponsorImageView];
- [UIView animateWithDuration:IN_OUT_DURATION delay:0 options:UIViewAnimationOptionCurveLinear
- animations:^{
- CGRect rect = sponsorImageView.frame;
- rect.origin.x = viewRect.size.width/2 - rect.size.width/2;
- sponsorImageView.frame = rect;
- }
- completion:^(BOOL finished) {
- //start timer
- self.timer = [NSTimer scheduledTimerWithTimeInterval:STAY_DURATION
- target:self
- selector:@selector(timerGoAway:)
- userInfo:nil repeats:NO];
- }];
- }
- else {
- [UIView animateWithDuration:1 delay:0.1 options:UIViewAnimationOptionCurveLinear
- animations:^{
- splashView.alpha = 0;
- }
- completion:^(BOOL finished) {
- [self.view removeFromSuperview];
- [splashView release];
- splashView = nil;
- }];
- }
- }
- - (void)runGoingAnimation:(NSUInteger)index {
- if (index < [sponsorsImageViews count]) {
- UIImageView *sponsorImageView = [sponsorsImageViews objectAtIndex:index];
- [UIView animateWithDuration:IN_OUT_DURATION delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
- animations:^{
- CGRect rect = sponsorImageView.frame;
- rect.origin.x = -rect.size.width;
- sponsorImageView.frame = rect;
- }
- completion:^(BOOL finished) {
- [self runComingAnimation:index+1];
- }];
- }
- else {
- [UIView animateWithDuration:1 delay:0.1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
- animations:^{
- splashView.alpha = 0;
- }
- completion:^(BOOL finished) {
- [self.view removeFromSuperview];
- [splashView release];
- splashView = nil;
- }];
- }
- }
- - (void)timerGoAway:(NSTimer *)aTimer {
- self.timer = nil;
- [self runGoingAnimation:currentIndex];
- }
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
- if (self.timer != nil) {
- //[self retain]; //WOWOA WARNING BIG ASS HACK HERE
- [self.timer invalidate];
- [self timerGoAway:nil];
- }
- }
- - (void)dealloc {
- [sponsorsImageViews release];
- [splashView release];
- [timer release];
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement