// // WPDetailViewController.m #import "AWM_DetailViewController.h" #import "AppDelegate.h" #import "AWM_WallPapaerADManager.h" #define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_h [UIScreen mainScreen].bounds.size.height #define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f] @interface AWM_DetailViewController () @property(nonatomic,strong)UIButton *backItem; @property(nonatomic,strong)UIButton *navImage; @property(nonatomic,strong)UIScrollView *wpscroll; @property(nonatomic,assign)NSInteger index; @end @implementation AWM_DetailViewController - (void)backItemEventLove:(id)sender{ __weak typeof(self) weakSelf = self; [[AWM_WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) { [weakSelf.navigationController popViewControllerAnimated:YES]; }]; // [self.navigationController popViewControllerAnimated:YES]; } - (void)saveItemEventLove:(id)sender{ UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:self.data[self.index]], self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil); AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [app.saveImages addObject:self.data[self.index]]; } - (void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { if (!error) { UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Save Success" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil]; [iconAl show]; } else { NSLog(@"%@", [error description]); } } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController.navigationBar addSubview:self.backItem]; [self.navigationController.navigationBar addSubview:self.navImage]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.backItem removeFromSuperview]; [self.navImage removeFromSuperview]; } - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.hidesBackButton = YES; self.view.backgroundColor = WP_COLOR_WITH_HEX(0xF2C4D5); NSString *backitem = KLS(@"back", @"A friendly greeting"); UIButton *backItem = [[UIButton alloc] initWithFrame:CGRectMake(20-1,0-1,74-1,44-1)]; [backItem setImage:[UIImage imageNamed:backitem] forState:UIControlStateNormal]; [backItem addTarget:self action:@selector(backItemEventLove:) forControlEvents:UIControlEventTouchUpInside]; self.backItem = backItem; UIButton *navImage = [[UIButton alloc] initWithFrame:CGRectMake(WPScreen_w-100-1,2-1,74-1,40-1)]; NSString *save = KLS(@"save", @"A friendly greeting"); [navImage setImage:[UIImage imageNamed:save] forState:UIControlStateNormal]; [navImage addTarget:self action:@selector(saveItemEventLove:) forControlEvents:UIControlEventTouchUpInside]; self.navImage = navImage; UIScrollView *wpscroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0-1,150-1,WPScreen_w-1,WPScreen_h-350-1)]; wpscroll.pagingEnabled = YES; wpscroll.delegate = self; [self.view addSubview:wpscroll]; self.wpscroll = wpscroll; for (int i = 0; i < self.data.count; i ++) { UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(i*wpscroll.frame.size.width-1,0-1,wpscroll.frame.size.width-1,wpscroll.frame.size.height-1)]; iconImg.image = [UIImage imageNamed:self.data[i]]; iconImg.contentMode = UIViewContentModeScaleAspectFill; [wpscroll addSubview:iconImg]; } [wpscroll setContentSize:CGSizeMake(WPScreen_w*self.data.count, wpscroll.frame.size.height)]; UIButton *shangItem = [[UIButton alloc] initWithFrame:CGRectMake((WPScreen_w-240)/3-1,WPScreen_h-170-1,120-1,50-1)]; NSString *shang = KLS(@"shang", @"A friendly greeting"); [shangItem setImage:[UIImage imageNamed:shang] forState:UIControlStateNormal]; [shangItem addTarget:self action:@selector(shangItemEventLove:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:shangItem]; UIButton *xiaItem = [[UIButton alloc] initWithFrame:CGRectMake((WPScreen_w-240)/3*2+120-1-1,WPScreen_h-170-1-1,120-1-1,50-1-1)]; NSString *xia = KLS(@"xia", @"A friendly greeting"); [xiaItem setImage:[UIImage imageNamed:xia] forState:UIControlStateNormal]; [xiaItem addTarget:self action:@selector(xiaItemEventLove:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:xiaItem]; } - (void)shangItemEventLove:(id)sender{ if (self.index == 0) { UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"It's already the first one" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil]; [iconAl show]; return; } self.index --; [self.wpscroll setContentOffset:CGPointMake(self.index*WPScreen_w, 0)]; } - (void)xiaItemEventLove:(id)sender{ if (self.index == self.data.count-1) { UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"It's the last one" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil]; [iconAl show]; return; } self.index ++; [self.wpscroll setContentOffset:CGPointMake(self.index*WPScreen_w, 0)]; } - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{ self.index = scrollView.contentOffset.x; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ self.index = scrollView.contentOffset.x/WPScreen_w; NSLog(@"... %d",self.index); } @end