热更新demo

ImageContentController.m 28KB

    // // TPImageBroserViewController.m // ThePaperDemo // // Created by YoungLee on 15/6/17. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "ImageContentController.h" #import "AsyncImageScrollView.h" #import "DescView.h" #import "hotImageListController.h" #import "commentAndAskController.h" #import "shareContent.h" #import "ImageListViewModel.h" #import "loginHomeController.h" #define COLLECTTAG 1002 #define CANCELCOLLECTTAG 1003 #define VIEWTAG 10086 #define VIEWWIDTH CGRectGetWidth(self.view.bounds) #define SHARECONTENTTAG 2500 @interface ImageContentController () <askDelegate,shareContentDelegate,ImageListViewModelDelegate> { int tempY; int navHeight; NSString *desc; NSString *tagstr; BOOL _isTap; UIView *tagView; CAGradientLayer *gradientLayer; } @property(nonatomic, assign)CGFloat statusHeight; @property(nonatomic, strong)contentObjectBO *contentBO; @property(nonatomic, strong)UIView *maskView; @property(nonatomic, strong)ImageListViewModel *model; @property(nonatomic, strong)commentAndAskController *askCommentController; @property(nonatomic, strong)NSMutableArray *contentImageList; @property(nonatomic, strong)UIButton *interActionBtn; @property(nonatomic, strong)UIView *contentView; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UISwipeGestureRecognizer *leftSwipeGesture; @property(nonatomic, strong)NSMutableArray *commentList; @property(nonatomic, strong)NSMutableDictionary *qaDataDic; @property(nonatomic, strong)UIButton *backButton; @property(nonatomic, strong)UIButton *shareButton; @property(nonatomic, strong)UIButton *favorButton; @property(nonatomic, strong)UIButton *commentButton; @property(nonatomic, strong)UIButton *downLoadButton; @property(nonatomic, strong)NSMutableArray *hotImageList; @property(nonatomic, assign)NSInteger actionFlag; @end @implementation ImageContentController @synthesize nodeID = _nodeID; @synthesize statusHeight,firstPan; @synthesize contentBO = _contentBO; @synthesize contentImageList; @synthesize currentIndex = _currentIndex; @synthesize leftSwipeGesture; @synthesize commentList,qaDataDic; @synthesize hotImageList; @synthesize actionFlag = _actionFlag; @synthesize startTouch; @synthesize enablePan; - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"7"]; if (isIOS7) { self.statusHeight = 18; }else { self.statusHeight = 0; } _isTap = NO; self.toolBarView = [[UIView alloc]init]; self.toolBarView.backgroundColor = [UIColor clearColor]; if (isIOS7) { self.toolBarView.frame = CGRectMake(0, 0, self.view.frame.size.width, 45+18); tempY = 18 + 15; navHeight = 63; }else { self.toolBarView.frame = CGRectMake(0, 0, self.view.frame.size.width, 45); tempY = 0 + 15; navHeight = 45; } self.saveButton.hidden = YES; self.backBtn.hidden = YES; [self.toolBarView addSubview:self.backMaskImageView]; __weak typeof(self) weakSelf = self; [self.backMaskImageView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.toolBarView.left); make.right.equalTo(weakSelf.toolBarView.right); make.top.equalTo(weakSelf.toolBarView.top); make.height.mas_equalTo(133.5); }]; [self.toolBarView addSubview:self.backButton]; [self.toolBarView addSubview:self.commentButton]; [self.toolBarView addSubview:self.downLoadButton]; [self.toolBarView addSubview:self.shareButton]; [self.toolBarView addSubview:self.favorButton]; [self.view addSubview:self.toolBarView]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissCommentView:)]; tapGesture.delaysTouchesBegan = YES; [self.maskView addGestureRecognizer:tapGesture]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; self.currentIndex = 0; [self startHud]; self.actionFlag = 3; self.model = [[ImageListViewModel alloc] init]; self.model.nodeID = self.nodeID; self.model.delegate = self; [self.model remoteAction]; tagView = [[UIView alloc] initWithFrame:CGRectMake(0, rect_screen.size.height-38.5, rect_screen.size.width, 38.5)]; [self.view addSubview:tagView]; gradientLayer = [CAGradientLayer layer]; gradientLayer.borderWidth = 0; gradientLayer.frame = tagView.bounds; gradientLayer.colors = @[(id)[UIColor clearColor].CGColor,(id)[UIColor colorWithRed:0 green:0 blue:0 alpha:0.8].CGColor]; [tagView.layer insertSublayer:gradientLayer atIndex:0]; tagView.userInteractionEnabled = NO; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; ((MLNavigationController *)self.navigationController).canDragBack = NO; /** * bug:5363(图集在非第一张图片页面,从图说位置左滑会直接退出该图集) */ if (self.currentIndex == 0) { self.rightGesture.enabled = YES; }else { self.rightGesture.enabled = NO; } } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { // 横屏 [self layoutSubViewsH]; shareContent *shareContentView = (shareContent*)[self.view viewWithTag:SHARECONTENTTAG]; if (shareContentView) { [shareContentView dismissShareContent]; } }else { // 竖屏 [self layoutSubViewsV]; } } - (BOOL) shouldAutorotate { return YES; } -(UIInterfaceOrientationMask)supportedInterfaceOrientations { return self.shouldV?UIInterfaceOrientationMaskPortrait: UIInterfaceOrientationMaskAllButUpsideDown; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return self.shouldV ? UIInterfaceOrientationMaskPortrait : UIInterfaceOrientationMaskAllButUpsideDown; } - (void)statusBarOrientationChange:(NSNotification *)notification { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; // id vc = self.pagesList[self.c] if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { self.commentButton.hidden = YES; self.shareButton.hidden = YES; self.downLoadButton.hidden = YES; self.favorButton.hidden = YES; }else { self.commentButton.hidden = NO; self.shareButton.hidden = NO; self.downLoadButton.hidden = NO; self.favorButton.hidden = NO; } self.currentIndex = _currentIndex; tagView.frame = CGRectMake(0, rect_screen.size.height-38.5, rect_screen.size.width, 38.5); gradientLayer.frame = tagView.bounds; } - (void)layoutSubViewsH { __weak typeof(self) weakSelf = self; [_backButton remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.toolBarView.left).offset(10); make.bottom.equalTo(weakSelf.toolBarView.bottom).offset(-20); make.height.mas_equalTo(30); make.width.mas_equalTo(30); }]; _commentButton.hidden = YES; _shareButton.hidden = YES; _downLoadButton.hidden = YES; _favorButton.hidden = YES; } - (void)layoutSubViewsV { __weak typeof(self) weakSelf = self; [_favorButton remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.toolBarView.right).offset(-20); make.bottom.equalTo(weakSelf.toolBarView.bottom); make.width.equalTo(@30); make.height.equalTo(@30); }]; [_shareButton remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.favorButton.left).offset(-20); make.bottom.equalTo(weakSelf.toolBarView.bottom); make.width.equalTo(@30); make.height.equalTo(@30); }]; [_downLoadButton remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.shareButton.left).offset(-20); make.bottom.equalTo(weakSelf.toolBarView.bottom); make.width.equalTo(@30); make.height.equalTo(@30); }]; [_backButton remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.toolBarView.left).offset(10); make.bottom.equalTo(weakSelf.toolBarView.bottom); make.height.mas_equalTo(30); make.width.mas_equalTo(30); }]; [_commentButton remakeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(weakSelf.downLoadButton.left).offset(-20); make.bottom.equalTo(weakSelf.toolBarView.bottom); make.width.equalTo(@30); make.height.equalTo(@30); }]; } #pragma mark - set and get method - (void)setActionFlag:(NSInteger)flag { _actionFlag = flag; if (flag == 0) { [self stopHud]; } } - (void)setNodeID:(NSString *)nodeStr { _nodeID = nodeStr; } - (UIButton *)favorButton { if (!_favorButton) { _favorButton = [UIButton buttonWithType:UIButtonTypeCustom]; // _favorButton.frame = CGRectMake(CGRectGetMaxX(self.shareButton.frame)+20, tempY, 30, 30); [_favorButton setImage:Image(@"imageList/favorBtn.png") forState:UIControlStateNormal]; [_favorButton setImage:Image(@"imageList/favorBtnHighLight.png") forState:UIControlStateHighlighted]; [_favorButton setImage:Image(@"imageList/favorBtnSelect.png") forState:UIControlStateSelected]; [_favorButton setImageEdgeInsets:self.commentButton.imageEdgeInsets]; [_favorButton addTarget:self action:@selector(favor:) forControlEvents:UIControlEventTouchUpInside]; } return _favorButton; } - (UIButton *)shareButton { if (!_shareButton) { _shareButton = [UIButton buttonWithType:UIButtonTypeCustom]; _shareButton.frame = CGRectMake(CGRectGetMaxX(self.downLoadButton.frame)+20, tempY, 30, 30); [_shareButton setImage:Image(@"imageList/shareBtn.png") forState:UIControlStateNormal]; [_shareButton setImage:Image(@"imageList/shareBtnHighLight.png") forState:UIControlStateHighlighted]; [_shareButton setImageEdgeInsets:_commentButton.imageEdgeInsets]; [_shareButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside]; } return _shareButton; } - (commentAndAskController *)askCommentController { if (!_askCommentController) { _askCommentController = [[commentAndAskController alloc] init]; _askCommentController.delegate = self; _askCommentController.view.frame = CGRectMake(0, 0, rect_screen.size.width, rect_screen.size.height); [_askCommentController disablePanGesture]; } return _askCommentController; } - (UIButton *)commentButton { if (!_commentButton) { _commentButton = [UIButton buttonWithType:UIButtonTypeCustom]; _commentButton.frame = CGRectMake(CGRectGetMaxX(self.backButton.frame)+90, tempY, 30, 30); [_commentButton addTarget:self action:@selector(comment:) forControlEvents:UIControlEventTouchUpInside]; [_commentButton setImage:Image(@"imageList/comment.png") forState:UIControlStateNormal]; [_commentButton setImage:Image(@"imageList/commentHighLight.png") forState:UIControlStateHighlighted]; [_commentButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(_commentButton.bounds)/2-25/2, CGRectGetWidth(_commentButton.bounds)/2-25/2, CGRectGetHeight(_commentButton.bounds)/2-25/2, CGRectGetWidth(_commentButton.bounds)/2-25/2)]; } return _commentButton; } - (UIButton *)backButton { if (!_backButton) { _backButton = [UIButton buttonWithType:UIButtonTypeCustom]; _backButton.frame = CGRectMake(10, tempY, 30, 30); [_backButton addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside]; [_backButton setImage:Image(@"imageList/backBtn.png") forState:UIControlStateNormal]; [_backButton setImageEdgeInsets:UIEdgeInsetsMake(CGRectGetHeight(_backButton.bounds)/2-20/2, CGRectGetWidth(_backButton.bounds)/2-20/2, CGRectGetHeight(_backButton.bounds)/2-20/2, CGRectGetWidth(_backButton.bounds)/2-20/2)]; } return _backButton; } - (UIView*)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 2*self.view.frame.size.width, self.view.frame.size.height)]; _backView.backgroundColor = [UIColor whiteColor]; } return _backView; } - (UIView*)contentView { if (!_contentView) { _contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VIEWWIDTH, CGRectGetHeight(self.backView.frame))]; _contentView.backgroundColor = [UIColor whiteColor]; } return _contentView; } - (UIButton *)downLoadButton { if (!_downLoadButton) { _downLoadButton = [UIButton buttonWithType:UIButtonTypeCustom]; _downLoadButton.frame = CGRectMake(CGRectGetMaxX(self.commentButton.frame)+20, tempY, 30, 30); [_downLoadButton setImage:Image(@"imageList/downLoadBtn.png") forState:UIControlStateNormal]; [_downLoadButton setImage:Image(@"imageList/downLoadBtnHighLight.png") forState:UIControlStateHighlighted]; [_downLoadButton setImageEdgeInsets:self.commentButton.imageEdgeInsets]; [_downLoadButton addTarget:self action:@selector(downLoad:) forControlEvents:UIControlEventTouchUpInside]; } return _downLoadButton; } - (void)setDescVIewWith:(NSString *)content andTagString:(NSString *)tagString { if (self.descView) { [self.descView removeFromSuperview]; self.descView = [[DescView alloc] initWithDescString:content tagString:tagString]; [self.view insertSubview:self.descView aboveSubview:tagView]; }else { self.descView = [[DescView alloc] initWithDescString:content tagString:tagString]; [self.view insertSubview:self.descView belowSubview:tagView]; } if (_isTap) { CGRect descrect = self.descView.frame; descrect.origin.y = rect_screen.size.height; self.descView.frame = descrect; CGRect navrect = self.toolBarView.frame; navrect.origin.y -= navrect.size.height; self.toolBarView.frame = navrect; self.descView.hidden = YES; self.toolBarView.hidden = YES; } } - (void)setCurrentIndex:(NSInteger)index { _currentIndex = index; CGFloat temp = 0; if (_isTap) { temp = -navHeight; } __weak typeof(self) weakSelf = self; [self.toolBarView remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(weakSelf.view.left); make.right.mas_equalTo(weakSelf.view.right); make.top.mas_equalTo(weakSelf.view.top).offset(temp); make.height.mas_equalTo(navHeight); }]; imageObjectBO *image = self.imageBOList[self.currentIndex]; if (isBlankString(image.desc)) { desc = @""; } else { if ([TPUserDefault instance].isUseSystemFont.integerValue == 0) { desc = [NSString stringWithFormat:@" %@",image.desc]; if (index > 8) { desc = [NSString stringWithFormat:@" %@",desc]; } }else { desc = [NSString stringWithFormat:@" %@",image.desc]; if (index > 8) { desc = [NSString stringWithFormat:@" %@",desc]; } } } tagstr = [NSString stringWithFormat:@"%ld/%ld",(long)index+1,(long)self.imageBOList.count]; [self setDescVIewWith:desc andTagString:tagstr]; self.numLabel.frame = CGRectMake(CGRectGetWidth(self.toolBarView.bounds)/2-190/4, CGRectGetHeight(self.toolBarView.bounds)-80, 190/2, 50); self.interActionBtn.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-320, CGRectGetHeight(self.toolBarView.frame)-138/2, 65/2, 56/2); self.gradientLayer.frame = self.toolBarView.bounds; self.maskView.frame = self.view.bounds; } - (void)setContentBO:(contentObjectBO *)contentData { if (!contentData) { TPLOG(@"返回数据有误!"); return; } _contentBO = contentData; } #pragma mark - selectors - (void)back:(id)sender { // self.shouldV = YES; // [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; [UIView animateWithDuration:0.25 animations:^{ self.shouldV = YES; [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"]; } completion:^(BOOL finished) { [self.navigationController popViewControllerAnimated:YES]; }]; } - (void)downLoad:(id)sender //下载 { if (!self.imageBOList || self.imageBOList.count == 0) { return; } AsyncImageScrollView *asyImageView = self.pagesList[self.currentIndex]; [self.model saveImage:asyImageView]; } - (void)favor:(UIButton *)btn //手残 { if (!btn.selected) { if (![TPUserDefault instance].userBO) { loginHomeController *vc = [loginHomeController new]; [self.navigationController pushViewController:vc animated:YES]; return; } [self.model collectContent]; }else { if (![TPUserDefault instance].userBO) { loginHomeController *vc = [loginHomeController new]; [self.navigationController pushViewController:vc animated:YES]; return; } [self.model cancelCollect]; } } - (void)presentLoginModal:(void (^)(void))completion dismiss:(void (^)(void))dismiss { // 判断登录 } - (void)comment:(id)sender //评论 { self.rightGesture.enabled = NO; ((MLNavigationController *)self.navigationController).canDragBack = YES; [self.navigationController pushViewController:self.askCommentController animated:YES]; } - (void)removeButtonHandler { [self.navigationController popViewControllerAnimated:YES]; } - (void)share:(UIButton *)btn //分享 { if (!btn.selected) { shareContent *shareContentView = [[shareContent alloc]initWithFrame:self.view.bounds]; shareContentView.delegate = self; shareContentView.tag = SHARECONTENTTAG; shareContentView.contentBO = self.contentBO; shareContentView.baseController = self; [shareContentView presentShareContentInView:self.view sender:btn]; }else { shareContent *shareContentView = (shareContent*)[self.view viewWithTag:SHARECONTENTTAG]; if (shareContentView) { [shareContentView dismissShareContent]; } } } - (void)interActionHander:(UIButton*)btn { [UIView animateWithDuration:0.25 animations:^{ [self.view addSubview:self.maskView]; self.maskView.alpha = 0.6f; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ } completion:^(BOOL finished) { self.leftSwipeGesture.enabled = NO; }]; }]; } - (void)leftSwipeHandler:(id)sender { [self back:nil]; } - (void)singleTapGestureHandler { if (_isTap == NO) { CGRect navrect = self.toolBarView.frame; navrect.origin.y -= navrect.size.height; CGRect descrect = self.descView.frame; descrect.origin.y = rect_screen.size.height; [UIView animateWithDuration:0.35 animations:^{ self.toolBarView.frame = navrect; self.descView.frame = descrect; }]; } else { self.descView.hidden = NO; self.toolBarView.hidden = NO; CGRect navrect = self.toolBarView.frame; navrect.origin.y = 0; CGRect descrect = self.descView.frame; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { descrect.origin.y = rect_screen.size.height - ([iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace] + appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO).lineHeight)*3-3; }else { descrect.origin.y = rect_screen.size.height - ([iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace] + appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO).lineHeight)*5-3; } [UIView animateWithDuration:0.35 animations:^{ self.toolBarView.frame = navrect; self.descView.frame = descrect; }]; } _isTap = !_isTap; } #pragma mark - remote delegate - (void)didDismissShareContent:(UIView *)contentView { contentView = nil; } - (void)startHud { [self.view addSubview:self.waitBackView]; [self.view bringSubviewToFront:self.waitBackView]; self.waitCursor.animating = YES; } - (void)stopHud { [self.waitBackView removeFromSuperview]; self.waitBackView = nil; self.waitCursor.animating = NO; } - (void)startHudAnimation { [self startHud]; } - (void)stopHudAnimation { [self stopHud]; } #pragma mark - viewModel delegate - (void)returnImageBOList:(NSMutableArray *)list cotentBO:(contentObjectBO *)contentOBJ{ self.actionFlag = self.actionFlag -1; self.contentBO = contentOBJ; self.imageBOList = list; self.currentIndex = 0; NSString *isFavorited = contentOBJ.isFavorited?contentOBJ.isFavorited:@""; if (!isBlankString(isFavorited) && [isFavorited intValue] == 1 && [TPUserDefault instance].userBO) { [self.favorButton setSelected:YES]; }else { [self.favorButton setSelected:NO]; } self.askCommentController.view.hidden = NO; } - (void)returnHotImageList:(NSMutableArray *)list { self.hotList = list; } - (void)returnCommentList:(NSMutableArray *)commentArray nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl commentTotalRecord:(NSInteger)recordTotal { self.actionFlag = self.actionFlag -1; self.askCommentController.nodeId = nodeId; self.askCommentController.commentList = commentArray; self.askCommentController.firstCommentUrl = nextUrl; self.askCommentController.commentSum = recordTotal; } - (void)returnHotAskDic:(NSMutableDictionary *)qaDic nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl askTotalRecord:(NSInteger)recordTotal { self.actionFlag = self.actionFlag -1; self.askCommentController.dataDic = qaDic; self.askCommentController.firstAskUrl = nextUrl; self.askCommentController.qaNum = recordTotal; } - (void)collectResult:(BOOL)success { if (success) { [self stopHud]; [self.favorButton setSelected:YES]; }else { [self stopHud]; [self.favorButton setSelected:NO]; } } - (void)remoteFail:(BOOL)isTimeOut{ [self stopHud]; if (isTimeOut) { [self networkTimeOut]; } } - (void)contentHaveOffline { [self stopHud]; [self contentHaveOfflined]; } - (void)refreshPage { [self.timeOutView removeFromSuperview]; [self.model remoteAction]; } #pragma mark - network time out - (void)networkTimeOut { [self.timeOutView removeFromSuperview]; self.timeOutView = nil; self.timeOutView = [[UIView alloc]initWithFrame:CGRectZero]; self.timeOutView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.timeOutView.frame = self.view.bounds; self.timeOutView.autoresizingMask = AutoresizingFull; UIButton *refreshBtn = [UIButton buttonWithType:UIButtonTypeCustom]; refreshBtn.frame = self.timeOutView.bounds; [refreshBtn setImage:Image(@"other/pageRefresh.png") forState:UIControlStateNormal]; [refreshBtn setImage:Image(@"other/pageRefresh_h.png") forState:UIControlStateHighlighted]; [refreshBtn addTarget:self action:@selector(refreshPageAfterTimeOut) forControlEvents:UIControlEventTouchUpInside]; refreshBtn.autoresizingMask = AutoresizingFull; [self.timeOutView addSubview:refreshBtn]; UILabel *timeOutLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.timeOutView.bounds)/2+41/2+20, CGRectGetWidth(self.timeOutView.bounds), 25)]; timeOutLabel.font = appFont(20, NO); timeOutLabel.textAlignment = NSTextAlignmentCenter; timeOutLabel.textColor = [UIColor colorWithHexString:TextBlack]; timeOutLabel.text = @"网络不给力,点击重新加载"; timeOutLabel.autoresizingMask = AutoresizingAuto; [self.timeOutView addSubview:timeOutLabel]; [self.view addSubview:self.timeOutView]; [self.view bringSubviewToFront:self.timeOutView]; if (![self isKindOfClass:[newPageBaseController class]]) { UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0, 18, 40, 64-18); backBtn.backgroundColor = [UIColor clearColor]; if ([[TPUserDefault instance].isNightMode intValue] == 0) { [backBtn setImage:Image(@"detailPage/backBtn.png") forState:UIControlStateNormal]; [backBtn setImage:Image(@"detailPage/backBtn_s.png") forState:UIControlStateHighlighted]; }else { [backBtn setImage:Image(@"detailPage/backBtn_night.png") forState:UIControlStateNormal]; [backBtn setImage:Image(@"detailPage/backBtn_night_s.png") forState:UIControlStateHighlighted]; } [backBtn addTarget:self action:@selector(backHandler) forControlEvents:UIControlEventTouchUpInside]; [self.timeOutView addSubview:backBtn]; [backBtn makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.timeOutView.left); make.top.equalTo(self.timeOutView.top).offset(18); make.width.equalTo(@40); make.height.equalTo(@46); }]; } /** * bug:5565(【倒退】在图集和话题详情页中显示网络不给力,点击重新加载页面没有返回箭头) */ } - (void)backHandler { ((MLNavigationController *)self.navigationController).canDragBack = YES; [self.navigationController popViewControllerAnimated:YES]; } - (void)contentHaveOfflined{ self.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBarHidden = YES; // [self.view.subviews enumerateObjectsUsingBlock:^(UIView* obj, NSUInteger idx, BOOL *stop) { // if (![obj isEqual:self.naviBar]) { // [obj removeFromSuperview]; // } // }]; UILabel *textLabel = [[UILabel alloc]init]; textLabel.textAlignment = NSTextAlignmentCenter; textLabel.font = appFont(18, NO); textLabel.textColor = [UIColor colorWithHexString:TextBlack]; textLabel.text = @"此文章已下线"; textLabel.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [self.view addSubview:textLabel]; [self.view insertSubview:textLabel belowSubview:self.toolBarView]; [textLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.top.equalTo(self.view.bottom); make.bottom.equalTo(self.view.bottom); }]; } #pragma mark - dealloc and memmory warning - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end