澎湃iPad上线版本

operationNavigationController.m 9.1KB

    // // operationNavigationController.m // ThePaperHD // // Created by scar1900 on 15/4/1. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "operationNavigationController.h" #import "ATPagingView.h" #import "StyledPageControl.h" @interface operationNavigationController ()<ATPagingViewDelegate,UIGestureRecognizerDelegate> { BOOL hiddenStatusBar; } @property(nonatomic,strong)ATPagingView *pagingView; @property(nonatomic, strong)NSMutableArray *imageList; @property(nonatomic, strong)NSMutableArray *imagePoraitList; @property(nonatomic, strong)NSMutableArray *imageViewList; @property(nonatomic, strong)UISwipeGestureRecognizer *leftSwipeGesture; @property(nonatomic, strong)StyledPageControl *pageControl; //页码指示器 @end @implementation operationNavigationController @synthesize delegate; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; hiddenStatusBar = YES; //隐藏状态栏 if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; }else { [[UIApplication sharedApplication] setStatusBarHidden:hiddenStatusBar withAnimation:UIStatusBarAnimationFade]; } [self addPageView]; self.leftSwipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeGestureHandler:)]; [self.leftSwipeGesture delaysTouchesBegan]; self.leftSwipeGesture.numberOfTouchesRequired = 1; self.leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft; self.leftSwipeGesture.delegate = self; self.leftSwipeGesture.enabled = NO; [self.pagingView addGestureRecognizer:self.leftSwipeGesture]; [TPUserDefault instance].visitTime = @"0"; [self.view addSubview:self.pageControl]; self.pageControl.currentPage = self.pagingView.currentPageIndex; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { if (self.view.bounds.size.width > self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } }else { if (self.view.bounds.size.width < self.view.bounds.size.height) { self.view.frame =CGRectMake(0, 0, self.view.bounds.size.height, self.view.bounds.size.width); } } self.pagingView.frame = self.view.bounds; UIImageView *imageView = self.imageViewList[self.pagingView.currentPageIndex]; UIInterfaceOrientation ori = [[UIApplication sharedApplication] statusBarOrientation]; if (ori == UIInterfaceOrientationPortraitUpsideDown || ori == UIInterfaceOrientationPortrait) { imageView.image = self.imagePoraitList[self.pagingView.currentPageIndex]; [self.pageControl remakeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view.centerX); make.bottom.equalTo(self.view.bottom).offset(-115); make.height.equalTo(@10); make.width.equalTo(@31); }]; }else { imageView.image = self.imageList[self.pagingView.currentPageIndex]; [self.pageControl remakeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view.centerX); make.bottom.equalTo(self.view.bottom).offset(-55); make.height.equalTo(@10); make.width.equalTo(@31); }]; } // self.pageControl.frame= CGRectMake(0, CGRectGetHeight(self.view.bounds)-167, CGRectGetWidth(self.view.bounds), 10); // [self.pageControl remakeConstraints:^(MASConstraintMaker *make) { // make.centerX.equalTo(self.view.centerX); // make.bottom.equalTo(self.view.bottom).offset(-55); // make.height.equalTo(@10); // make.width.equalTo(@140); // }]; [self.pagingView didRotate]; } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } - (ATPagingView*)pagingView { if (!_pagingView) { _pagingView = [[ATPagingView alloc]initWithFrame:self.view.bounds]; _pagingView.gapBetweenPages = 0; _pagingView.recyclingEnabled = NO; _pagingView.backgroundColor = [UIColor whiteColor]; _pagingView.delegate = self; _pagingView.scrollView.bounces = NO; _pagingView.scrollView.scrollEnabled = YES; _pagingView.autoresizingMask = AutoresizingFull; } return _pagingView; } - (StyledPageControl *)pageControl { if (!_pageControl) { _pageControl = [[StyledPageControl alloc] initWithFrame:CGRectZero]; _pageControl.pageControlStyle = PageControlStyleThumb; _pageControl.userInteractionEnabled = NO; _pageControl.hidesForSinglePage = YES; _pageControl.thumbImage = Image(@"other/navigationImage_white.png"); _pageControl.selectedThumbImage = Image(@"other/navigationImage_blue.png"); // _pageControl.coreSelectedColor =[UIColor colorWithHexString:BLUECOLOR]; // _pageControl.coreNormalColor = [UIColor whiteColor]; _pageControl.strokeWidth = 5; _pageControl.gapWidth = 10; _pageControl.diameter = 13; _pageControl.backgroundColor = [UIColor clearColor]; } return _pageControl; } - (BOOL)prefersStatusBarHidden { return hiddenStatusBar; } - (void)addPageView { self.imageList = [NSMutableArray arrayWithObjects:Image(@"other/fistNavigationImage_1.png"), Image(@"other/fistNavigationImage_2.png"),nil];//直播页,日期栏口显示有两个症状(bug:3910) self.imagePoraitList = [NSMutableArray arrayWithObjects:Image(@"other/fistNavigationImage_1_p.png"), Image(@"other/fistNavigationImage_2_p.png"),nil]; [self.imageList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (nil == self.imageViewList) { self.imageViewList = [NSMutableArray array]; } [self.imageViewList addObject:[NSNull null]]; }]; [self.view addSubview:self.pagingView]; self.pageControl.numberOfPages = self.imageList.count; [self.pagingView reloadData]; } #pragma mark - pageView delegate - (NSInteger)numberOfPagesInPagingView:(ATPagingView *)pagingView { return self.imageViewList.count; } - (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index { id data = self.imageViewList[index]; if (data == [NSNull null]) { UIImageView *imageView = [[UIImageView alloc]init]; imageView.userInteractionEnabled = NO; imageView.frame = self.pagingView.bounds; self.imageViewList[index] = imageView; imageView.autoresizingMask = AutoresizingFull; data = imageView; } UIImageView *view = data; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortraitUpsideDown || orientation == UIInterfaceOrientationPortrait) { view.image = self.imagePoraitList[index]; }else { view.image = self.imageList[index]; } return self.imageViewList[index]; } - (void)currentPageDidChangeInPagingView:(ATPagingView *)pageView { if (pageView.currentPageIndex != self.imageViewList.count -1) { self.leftSwipeGesture.enabled = NO; }else self.leftSwipeGesture.enabled = YES; UIImageView *imageView = self.imageViewList[self.pagingView.currentPageIndex]; UIInterfaceOrientation ori = [[UIApplication sharedApplication] statusBarOrientation]; if (ori == UIInterfaceOrientationPortraitUpsideDown || ori == UIInterfaceOrientationPortrait) { imageView.image = self.imagePoraitList[self.pagingView.currentPageIndex]; }else { imageView.image = self.imageList[self.pagingView.currentPageIndex]; } self.pageControl.currentPage = self.pagingView.currentPageIndex; } - (void)pagesDidChangeInPagingView:(ATPagingView *)pageView { } - (void)pagingViewWillBeginMoving:(ATPagingView *)pageView { } - (void)pagingViewdDidScroll:(UIScrollView *)scrollerView { } - (void)leftSwipeGestureHandler:(id)sender { if ([self.delegate respondsToSelector:@selector(goOutOperateNavigateion)]) { [self.delegate goOutOperateNavigateion]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end