Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. @implementation SplashView
  3.  
  4. @synthesize timer;
  5.  
  6.  
  7. - (id)initWithSplashImage:(UIImage *)_splashImage sponsorsImages:(NSArray *)_images {
  8.     if ((self = [super initWithNibName:nil bundle:nil])) {
  9.         currentIndex = 0;
  10.         splashView = [[UIImageView alloc] initWithImage:_splashImage];
  11.         sponsorsImageViews = [[NSMutableArray alloc] initWithCapacity:[_images count]];
  12.        
  13.         for (UIImage *image in _images) {
  14.             UIImageView *sponsorImageView = [[UIImageView alloc] initWithImage:image];
  15.             [sponsorsImageViews addObject:sponsorImageView];
  16.             [sponsorImageView release];
  17.         }
  18.        
  19.         timer = nil;
  20.     }
  21.    
  22.     return self;   
  23. }
  24.  
  25.  
  26. - (void)loadView {
  27.     UIView *v = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  28.     self.view = v;
  29.     [v release];
  30. }
  31.  
  32.  
  33. - (void)viewDidLoad {
  34.     [super viewDidLoad];
  35.     [self.view addSubview:splashView];
  36. }
  37.  
  38.  
  39. - (void)viewDidAppear:(BOOL)animated {
  40.     [super viewDidAppear:animated];
  41.    
  42.     [self performSelector:@selector(runComingAnimation:) withObject:0 afterDelay:1];
  43. }
  44.  
  45.  
  46. - (void)runComingAnimation:(NSUInteger)index {
  47.     if (index < [sponsorsImageViews count]) {
  48.         currentIndex = index;
  49.        
  50.         UIImageView *sponsorImageView = [sponsorsImageViews objectAtIndex:index];
  51.         CGRect viewRect = self.view.frame;
  52.         CGRect rect = sponsorImageView.frame;
  53.         rect.origin.x = viewRect.size.width;
  54.         rect.origin.y = viewRect.size.height/2 - rect.size.height/2;
  55.         sponsorImageView.frame = rect;
  56.        
  57.         [self.view addSubview:sponsorImageView];
  58.        
  59.         [UIView animateWithDuration:IN_OUT_DURATION delay:0 options:UIViewAnimationOptionCurveLinear
  60.                          animations:^{
  61.                              CGRect rect = sponsorImageView.frame;
  62.                              rect.origin.x = viewRect.size.width/2 - rect.size.width/2;
  63.                              sponsorImageView.frame = rect;
  64.                          }
  65.                          completion:^(BOOL finished) {
  66.                              //start timer
  67.                              self.timer = [NSTimer scheduledTimerWithTimeInterval:STAY_DURATION
  68.                                                                            target:self
  69.                                                                          selector:@selector(timerGoAway:)
  70.                                                                          userInfo:nil repeats:NO];
  71.                          }];
  72.     }
  73.     else {
  74.         [UIView animateWithDuration:1 delay:0.1 options:UIViewAnimationOptionCurveLinear
  75.                          animations:^{
  76.                              splashView.alpha = 0;
  77.                          }
  78.                          completion:^(BOOL finished) {
  79.                              [self.view removeFromSuperview];
  80.                              [splashView release];
  81.                              splashView = nil;
  82.                          }];
  83.     }
  84. }
  85.  
  86.  
  87. - (void)runGoingAnimation:(NSUInteger)index {
  88.     if (index < [sponsorsImageViews count]) {
  89.         UIImageView *sponsorImageView = [sponsorsImageViews objectAtIndex:index];
  90.        
  91.         [UIView animateWithDuration:IN_OUT_DURATION delay:0 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
  92.                          animations:^{
  93.                              CGRect rect = sponsorImageView.frame;
  94.                              rect.origin.x = -rect.size.width;
  95.                              sponsorImageView.frame = rect;
  96.                          }
  97.                          completion:^(BOOL finished) {
  98.                              [self runComingAnimation:index+1];
  99.                          }];
  100.     }
  101.     else {
  102.         [UIView animateWithDuration:1 delay:0.1 options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionBeginFromCurrentState
  103.                          animations:^{
  104.                              splashView.alpha = 0;
  105.                          }
  106.                          completion:^(BOOL finished) {
  107.                              [self.view removeFromSuperview];
  108.                              [splashView release];
  109.                              splashView = nil;
  110.                          }];
  111.     }  
  112. }
  113.  
  114.  
  115. - (void)timerGoAway:(NSTimer *)aTimer {
  116.     self.timer = nil;
  117.     [self runGoingAnimation:currentIndex];
  118. }
  119.  
  120.  
  121. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
  122.     if (self.timer != nil) {
  123.         //[self retain]; //WOWOA WARNING BIG ASS HACK HERE
  124.         [self.timer invalidate];
  125.        
  126.         [self timerGoAway:nil];
  127.     }
  128. }
  129.  
  130. - (void)dealloc {
  131.     [sponsorsImageViews release];
  132.     [splashView release];
  133.     [timer release];
  134.     [super dealloc];
  135. }
  136.  
  137.  
  138. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement