Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. @interface AdViewController ()
  2. /** 定时器 */
  3. @property (nonatomic, strong) NSTimer *timer;
  4. @property (nonatomic, strong) UIButton *adButton;
  5. @end
  6.  
  7. @implementation AdViewController
  8.  
  9. NSUInteger secondsCountDown = 3;//倒计时秒数
  10.  
  11. - (void)viewDidLoad
  12. {
  13. [super viewDidLoad];
  14.  
  15. // 1.背景图片
  16. UIImageView *bg = [[UIImageView alloc] init];
  17. // 显示图片
  18. NSString *name=@"start_page_750x1334";
  19. if (kiPhone4_OR_4s) {
  20. name = @"start_page_640x960";
  21. } else if(kiPhone5_OR_5c_OR_5s){
  22. name = @"start_page_640x1136";
  23. } else if(kiPhone6_OR_6s){
  24. name = @"start_page_750x1334";
  25. } else if(kiPhone6Plus_OR_6sPlus){
  26. name = @"start_page_1242x2208";
  27. }
  28. // 为了释放图片内存,imageWithContentsOfFile 代替 [UIImage imageNamed:name];
  29. bg.image = kPNG_IMAGE_FILE(name);
  30. bg.frame = self.view.bounds;
  31. [self.view addSubview:bg];
  32.  
  33. // 2.广告图片
  34. SplashModel *splash = [SplashTool get];
  35. NSString *str = splash.imageUrl;
  36. UIImageView *adImageView = [[UIImageView alloc] init];
  37. adImageView.contentMode = UIViewContentModeScaleAspectFill;
  38. adImageView.clipsToBounds = YES;
  39. adImageView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight * 0.80);
  40. adImageView.userInteractionEnabled = YES;
  41. if (!str||str.length == 0) {
  42. adImageView.image = [UIImage imageNamed:@"start-mascot"];
  43. } else{
  44. [adImageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage new]];
  45. }
  46. UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(adImageViewTapped:)];
  47. tapGr.cancelsTouchesInView = NO;
  48. [adImageView addGestureRecognizer:tapGr];
  49. [self.view addSubview:adImageView];
  50.  
  51. // 3.多少秒后跳过,广告倒计时
  52. _adButton = [UIButton buttonWithType:UIButtonTypeCustom];
  53. _adButton.titleLabel.font = [UIFont systemFontOfSize:16];
  54. [_adButton setTitle:[NSString stringWithFormat:@"%lu 跳过",(unsigned long)secondsCountDown] forState:UIControlStateNormal];
  55. _adButton.backgroundColor = [UIColor whiteColor];
  56. [_adButton setTitleColor:COLOR_Text_Gay forState:UIControlStateNormal];
  57. [_adButton addTarget:self action:@selector(adSkipClick) forControlEvents:UIControlEventTouchUpInside];
  58. _adButton.frame = CGRectMake(kScreenWidth - 75, 25 , 60, 35);
  59. _adButton.titleLabel.font = XCFONT(14);
  60. _adButton.layer.cornerRadius = 2.5f;
  61. _adButton.layer.masksToBounds = YES;
  62. [self.view addSubview:_adButton];
  63.  
  64. _timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timerCountDown) userInfo:nil repeats:YES];
  65. [[NSRunLoop mainRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
  66. }
  67.  
  68. /**
  69. * 广告倒计时
  70. */
  71. - (void)timerCountDown
  72. {
  73. secondsCountDown--;
  74. if(secondsCountDown==0){
  75. [self adSkipClick];
  76. }
  77. }
  78.  
  79. /**
  80. * 点击跳过
  81. */
  82. - (void)adSkipClick
  83. {
  84. if (_timer.isValid) {
  85. [_timer invalidate];
  86. }
  87. _timer=nil;
  88.  
  89. [SwitchRootTool switchRootForViewController];
  90. }
  91.  
  92.  
  93. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement