| | |
| | | |
| | | #import "recommendViewController.h" |
| | | #import "recommendView.h" |
| | | @interface recommendViewController () |
| | | @interface recommendViewController ()<recommendViewDelegate> |
| | | @property (nonatomic,strong)recommendView *recommendView; |
| | | @property (nonatomic,strong)UIView *primtView; |
| | | @end |
| | | |
| | | @implementation recommendViewController |
| | |
| | | } |
| | | return self; |
| | | } |
| | | - (void)viewWillAppear:(BOOL)animated{ |
| | | [super viewWillAppear:animated]; |
| | | [self.navigationController.navigationBar setBackgroundColor:kGlobalMainColor]; |
| | | self.navigationController.navigationBar.barTintColor = kGlobalMainColor; |
| | | |
| | | // self.navigationController.navigationBar.translucent = NO; |
| | | } |
| | | - (void)viewDidLoad { |
| | | [super viewDidLoad]; |
| | | self.automaticallyAdjustsScrollViewInsets = NO; |
| | | // [self.navigationController.navigationBar setBackgroundColor:[UIColor orangeColor]]; |
| | | [self NetworkMonitoring]; |
| | | if(KIsiPhoneX){ |
| | | |
| | | } |
| | | [self.view addSubview:self.recommendView]; |
| | | [self.view addSubview:self.primtView]; |
| | | } |
| | | |
| | | - (void)refreshTaped:(UIButton *)sender{ |
| | | self.primtView.hidden = YES; |
| | | [self.recommendView loadDataFromFile]; |
| | | |
| | | } |
| | | #pragma mark - recommendViewDelegate |
| | | - (void)notHaveNetWork:(recommendView *)view{ |
| | | self.primtView.hidden = NO; |
| | | } |
| | | #pragma mark - getter |
| | | - (recommendView *)recommendView{ |
| | | if (_recommendView) { |
| | | return _recommendView; |
| | | } |
| | | |
| | | _recommendView = [[recommendView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; |
| | | _recommendView.delegate = self; |
| | | return _recommendView; |
| | | } |
| | | |
| | | #pragma mark 添加网络监测 |
| | | - (void)NetworkMonitoring{ |
| | | [[AFNetworkReachabilityManager sharedManager] startMonitoring]; |
| | | [[NSNotificationCenter defaultCenter] addObserver:self |
| | | selector:@selector(reachabilityChang:) |
| | | name:AFNetworkingReachabilityDidChangeNotification |
| | | object:nil]; |
| | | } |
| | | |
| | | - (void) reachabilityChang: (NSNotification*)note { |
| | | switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus) { |
| | | case AFNetworkReachabilityStatusNotReachable:{//无网 |
| | | [YTHsharedManger startManger].NetworkStatus = 0; |
| | | if (self.recommendView.dataHomeType.count == 0) { |
| | | self.primtView.hidden = NO; |
| | | }else{ |
| | | [self autoDisappearAlertTime:1 msg:@"网络不可用,请检查网络"]; |
| | | } |
| | | } |
| | | break; |
| | | case AFNetworkReachabilityStatusReachableViaWWAN:{//万维网 |
| | | [YTHsharedManger startManger].NetworkStatus = 1; |
| | | // [self.recommendView loadDataFromFile]; |
| | | |
| | | // [self performSelector:@selector(recordAotoStop) withObject:nil afterDelay:0.01]; |
| | | |
| | | } |
| | | break; |
| | | case AFNetworkReachabilityStatusReachableViaWiFi:{// 使用WiFi网络 |
| | | [YTHsharedManger startManger].NetworkStatus = 2; |
| | | // [self.recommendView loadDataFromFile]; |
| | | |
| | | // [self performSelector:@selector(recordAotoStop) withObject:nil afterDelay:0.01]; |
| | | // self.primtView.hidden = YES; |
| | | |
| | | |
| | | } |
| | | break; |
| | | case AFNetworkReachabilityStatusUnknown:{// 当前网络未知 |
| | | [YTHsharedManger startManger].NetworkStatus = 3; |
| | | |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | - (void)recordAotoStop{ |
| | | self.primtView.hidden = YES; |
| | | |
| | | } |
| | | - (UIView *)primtView{ |
| | | if (_primtView) { |
| | | return _primtView; |
| | | } |
| | | _primtView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; |
| | | // _primtView .backgroundColor = SJColor(98, 98,86 , 1); |
| | | _primtView.backgroundColor = [UIColor whiteColor]; |
| | | UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake((KScreenW - KScreenW / 3) / 2, KScreenH / 2 - KScreenW / 3 , KScreenW / 3 , KScreenW / 3)]; |
| | | imageview.image = [UIImage imageNamed: @"nowifi"]; |
| | | // imageview.backgroundColor = [UIColor orangeColor]; |
| | | [_primtView addSubview:imageview]; |
| | | |
| | | UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageview.frame), KScreenW , 30)]; |
| | | label.textColor = SJColor(98, 98, 98, 1); |
| | | label.text = @"无法连接到网络..."; |
| | | label.font = [UIFont boldSystemFontOfSize:18]; |
| | | label.textAlignment = NSTextAlignmentCenter; |
| | | [_primtView addSubview:label]; |
| | | UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; |
| | | button.frame = CGRectMake((KScreenW - KScreenW / 3) / 2, CGRectGetMaxY(label.frame) + 15, KScreenW / 3, 30); |
| | | button.backgroundColor = SJColor(25, 169, 249, 1); |
| | | button.titleLabel.font = [UIFont systemFontOfSize:16]; |
| | | [button setTitle:@"重新加载" forState:UIControlStateNormal]; |
| | | button.layer.cornerRadius = 5; |
| | | button.layer.masksToBounds = YES; |
| | | [button addTarget:self action:@selector(refreshTaped:) forControlEvents:UIControlEventTouchUpInside]; |
| | | [_primtView addSubview:button]; |
| | | _primtView.hidden = YES; |
| | | return _primtView; |
| | | } |
| | | |
| | | - (void)didReceiveMemoryWarning { |
| | | [super didReceiveMemoryWarning]; |