热更新demo

newPageBaseController.m 11KB

    // // newPageBaseController.m // ThePaperDemo // // Created by Scar on 14-9-15. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "newPageBaseController.h" #import "SCGIFImageView.h" #define backBtnTag 5500 #define timeOutTag 1024 @interface newPageBaseController () //@property(nonatomic, strong)SCGIFImageView *waitCursor; //@property(nonatomic, strong)UILabel *titleLabel; @end @implementation newPageBaseController @synthesize naviBar; @synthesize barHeight; @synthesize titleStr = _titleStr; @synthesize selfLineView; @synthesize isPresent; - (id)init { self = [super init]; if (self) { self.isPresent = NO; } return self; } - (CGFloat)barHeight { return self.naviBar.frame.size.height; } - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; [self.navigationController.navigationBar setHidden:YES]; self.naviBar = [[UIView alloc]init]; self.naviBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; if (isIOS7) { self.naviBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 45+18); }else { self.naviBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 45); } [self.view addSubview:self.naviBar]; selfLineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.naviBar.frame)-0.5, self.view.frame.size.width, 0.5)]; selfLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.naviBar addSubview:selfLineView]; UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; if (isIOS7) { backBtn.frame = CGRectMake(0, 18, 40, self.barHeight-18); }else { backBtn.frame = CGRectMake(0, 0, 40, self.barHeight); } backBtn.tag =backBtnTag; 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.naviBar addSubview:backBtn]; [self.naviBar addSubview:self.titleLabel]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapNaviBar:)]; [self.naviBar addGestureRecognizer:tapGesture]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightModeNewPageBase:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightModeNewPageBase:(NSNotification*)noti { self.naviBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; selfLineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; UIButton *backBtn = (UIButton*)[self.naviBar viewWithTag:backBtnTag]; 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]; } } - (void)backHandler { ((MLNavigationController *)self.navigationController).canDragBack = YES; if (!self.isPresent) { [self.navigationController popViewControllerAnimated:YES]; }else { [self dismissViewControllerAnimated:YES completion:^{ }]; } } //- (UIView *)waitBackView { // if (!_waitBackView) { // _waitBackView = [[UIView alloc]initWithFrame:CGRectMake(0, // self.barHeight, // CGRectGetWidth(self.view.bounds), // CGRectGetHeight(self.view.bounds))]; // _waitBackView.backgroundColor = [UIColor clearColor]; // [_waitBackView addSubview:self.waitCursor]; // } // _waitCursor.userInteractionEnabled = NO; // return _waitBackView; //} // //- (SCGIFImageView*)waitCursor { // if (!_waitCursor) { // NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingFormat:@"/%@", Bundle(@"frontPage/loading.gif")]; // NSData* imageData = [NSData dataWithContentsOfFile:filePath]; // _waitCursor = [[SCGIFImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.waitBackView.bounds)/2-25/2, // (CGRectGetHeight(self.waitBackView.bounds)-self.barHeight)/2-25/2, // 25, // 25)]; // _waitCursor.animating = YES; // [_waitCursor setData:imageData]; // _waitCursor.hidden = NO; // } // return _waitCursor; //} // //- (void) startWaitCursor:(int)actionTag { // [self.view addSubview:self.waitBackView]; //} // //- (void) stopWaitCursor:(int)actionTag { //// [UIView animateWithDuration:0.3 animations:^{ //// [self.waitBackView removeFromSuperview]; //// }]; // [self.waitBackView removeFromSuperview]; //} - (void)setTitleStr:(NSString *)str { _titleStr = str; self.titleLabel.text = str; if ([str isEqualToString:@""]) { self.titleLabel.hidden = YES; }else { self.titleLabel.hidden = NO; } } - (UILabel*)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(115/2, CGRectGetMaxY(self.naviBar.bounds)-35, CGRectGetWidth(self.naviBar.bounds)-115, 25)]; _titleLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _titleLabel.hidden = YES; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _titleLabel.textAlignment = NSTextAlignmentCenter; } _titleLabel.font = appFont(TEXT_ONE_PLUS_LEVELSIZE, NO); return _titleLabel; } - (void)tapNaviBar:(id)sender { } #pragma mark - content Offlined - (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]; [textLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.top.equalTo(self.naviBar.bottom); make.bottom.equalTo(self.view.bottom); }]; } - (void)topicHaveOfflined{ 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]; // } // }]; CGFloat statusH = 0; if (isIOS7) { statusH = 18; } 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]; [textLabel makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.right.equalTo(self.view.right); make.top.equalTo(self.naviBar.bottom); make.bottom.equalTo(self.view.bottom); }]; } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (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]; [self.timeOutView addSubview:refreshBtn]; UILabel *timeOutLabel = [[UILabel alloc]initWithFrame:CGRectZero]; timeOutLabel.font = appFont(20, NO); timeOutLabel.textAlignment = NSTextAlignmentCenter; timeOutLabel.textColor = [UIColor colorWithHexString:TextBlack]; timeOutLabel.text = @"网络不给力,点击重新加载"; timeOutLabel.autoresizingMask = AutoresizingAuto; timeOutLabel.tag = timeOutTag; [self.timeOutView addSubview:timeOutLabel]; [self.view addSubview:self.timeOutView]; [self.timeOutView makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; [refreshBtn makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.timeOutView); }]; [timeOutLabel makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.timeOutView.centerX); make.centerY.equalTo(self.timeOutView.centerY).offset(41/2+20); make.width.equalTo(self.timeOutView.width); make.height.equalTo(@25); }]; [self.view bringSubviewToFront:self.naviBar]; /** * bug:5587(关闭网络,进入专题页,”网络不给力,重新加载“该图标偏低) */ } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end