热更新demo

hotImageListController.m 13KB

    // // hotImageListController.m // ThePaperHD // // Created by scar1900 on 15/3/16. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "hotImageListController.h" #import "hotImageView.h" #import "ImageContentController.h" @interface hotImageListController ()<hotImgDelegate> @property(nonatomic, strong)UIView *firstView; @property(nonatomic, strong)UIView *secondView; @property(nonatomic, strong)UILabel *topic; @property(nonatomic, strong)UIButton *backBtn; @property(nonatomic, assign)BOOL shouldV; @property(nonatomic, strong)NSMutableArray *viewArray; @property(nonatomic, strong)hotImageView *view1; @property(nonatomic, strong)hotImageView *view2; @property(nonatomic, strong)hotImageView *view3; @property(nonatomic, strong)hotImageView *view4; @property(nonatomic, strong)hotImageView *view5; @property(nonatomic, strong)hotImageView *view6; @end @implementation hotImageListController @synthesize hotList= _hotList; @synthesize viewArray; - (void)viewDidLoad { //986 870 //241 160 //493 266 [super viewDidLoad]; [self.view addSubview:self.topic]; [self.view addSubview:self.firstView]; [self.view addSubview:self.secondView]; [self.topic addSubview:self.backBtn]; self.topic.userInteractionEnabled = YES; [self.firstView addSubview:self.view1]; [self.firstView addSubview:self.view2]; [self.firstView addSubview:self.view3]; [self.secondView addSubview:self.view4]; [self.secondView addSubview:self.view5]; [self.secondView addSubview:self.view6]; self.view.backgroundColor = [UIColor blackColor]; viewArray = [NSMutableArray arrayWithObjects:self.view1,self.view2,self.view3,self.view4,self.view5,self.view6, nil]; for (int i =0; i < viewArray.count; i++) { hotImageView *view = viewArray[i]; view.hotImgDelegate =self; view.contentBo = self.hotList[i]; } UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)]; swipe.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:swipe]; // self.view.backgroundColor = [UIColor redColor]; // Do any additional setup after loading the view. } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; ((MLNavigationController *)self.navigationController).canDragBack = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)setHotList:(NSMutableArray *)list{ _hotList = list; } -(UILabel *)topic{ if (!_topic) { _topic = [[UILabel alloc] initWithFrame:CGRectZero]; _topic.font = appFont(17, NO); _topic.textColor = [UIColor whiteColor]; _topic.textAlignment = NSTextAlignmentCenter; _topic.text = @"热门图集"; } return _topic; } - (void)swipe:(id)sender { [self backHanderEvent:self.backBtn]; } -(UIView *)firstView{ if (!_firstView) { _firstView = [[UIView alloc] initWithFrame:CGRectZero]; } return _firstView; } -(UIView *)secondView{ if (!_secondView) { _secondView = [[UIView alloc] initWithFrame:CGRectZero]; } return _secondView; } -(UIButton *)backBtn{ if (!_backBtn) { _backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _backBtn.frame = CGRectMake(10, 10, 30, 30); [_backBtn setImage:Image(@"imageList/backBtn.png") forState:UIControlStateNormal]; [_backBtn addTarget:self action:@selector(backHanderEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _backBtn; } -(hotImageView *)view1{ if (!_view1) { _view1 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view1; } -(hotImageView *)view2{ if (!_view2) { _view2 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view2; } -(hotImageView *)view3{ if (!_view3) { _view3 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view3; } -(hotImageView *)view4{ if (!_view4) { _view4 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view4; } -(hotImageView *)view5{ if (!_view5) { _view5 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view5; } -(hotImageView *)view6{ if (!_view6) { _view6 = [[hotImageView alloc] initWithFrame:CGRectZero]; } return _view6; } - (void)statusBarOrientationChange:(NSNotification *)notification { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { [self layOutSubViewForH]; }else { [self layOutSubViewForV]; } self.backBtn.frame = CGRectMake(20, CGRectGetHeight(self.view.frame)-80, 50, 80); } #pragma mark - button event - (void)backHanderEvent:(UIButton*)btn { [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)viewWillLayoutSubviews{ [super viewWillLayoutSubviews]; self.topic.frame = CGRectMake(0, 40, CGRectGetWidth(self.view.bounds), 50); // self.firstView.frame = CGRectMake(10, 157, 493, 435); UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { // 横屏 [self layOutSubViewForH]; [self.topic remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left); make.top.mas_equalTo(self.view.top).offset(4); make.right.mas_equalTo(self.view.right); make.bottom.mas_equalTo(self.view.top).offset(54); }]; }else { // 竖屏 [self layOutSubViewForV]; [self.topic remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left); make.top.mas_equalTo(self.view.top).offset(22); make.right.mas_equalTo(self.view.right); make.bottom.mas_equalTo(self.view.top).offset(72); }]; } // //// self.view1.frame = CGRectMake(0, 0, 241, 160); //// self.view2.frame = CGRectMake(251,0, 241, 160); //// self.view3.frame = CGRectMake(CGRectGetMinX(self.view1.frame), CGRectGetHeight(self.firstView.bounds)-266, 493, 266); //// //// self.view4.frame = CGRectMake(0, 0, 241, 160); //// self.view5.frame = CGRectMake(CGRectGetMaxX(self.view4.frame)+10, CGRectGetMinY(self.view4.frame), 241, 160); //// self.view6.frame = CGRectMake(CGRectGetMinX(self.view4.frame), CGRectGetMaxY(self.view4.frame)+10, 493, 266); } - (void)layOutSubViewForH { CGFloat height = 86*rect_screen.size.width/568; CGFloat width = (rect_screen.size.width-152)/3; CGFloat top = 80*rect_screen.size.width/568; [_firstView remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left).offset(74); make.right.mas_equalTo(self.view.right).offset(-74); make.top.mas_equalTo(self.view.top).offset(top); make.height.mas_equalTo(height); }]; [_secondView remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left).offset(74); make.right.mas_equalTo(self.view.right).offset(-74); make.top.mas_equalTo(self.firstView.bottom).offset(2); make.height.mas_equalTo(height); }]; [_view1 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.firstView); make.width.mas_equalTo(width); make.top.mas_equalTo(self.firstView.top); make.height.mas_equalTo(height); }]; [_view2 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view1.right).offset(2); make.width.mas_equalTo(width); make.top.mas_equalTo(self.firstView.top); make.height.mas_equalTo(height); }]; [_view3 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view2.right).offset(2); make.width.mas_equalTo(width); make.top.mas_equalTo(self.firstView.top); make.height.mas_equalTo(height); }]; [_view4 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.secondView); make.width.mas_equalTo(width); make.top.mas_equalTo(self.secondView.top); make.height.mas_equalTo(height); }]; [_view5 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view4.right).offset(2); make.width.mas_equalTo(width); make.top.mas_equalTo(self.secondView.top); make.height.mas_equalTo(height); }]; [_view6 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view5.right).offset(2); make.width.mas_equalTo(width); make.top.mas_equalTo(self.secondView.top); make.height.mas_equalTo(height); }]; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } - (void)layOutSubViewForV { CGFloat height = 87*rect_screen.size.height/568; CGFloat height1 = 152*rect_screen.size.height/568; CGFloat height2 = 215*rect_screen.size.height/568; [self.firstView remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left).offset(20); make.right.mas_equalTo(self.view.right).offset(-20); make.top.mas_equalTo(self.view.top).offset(72); make.height.mas_equalTo(height2); }]; [_secondView remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view.left).offset(20); make.right.mas_equalTo(self.view.right).offset(-20); make.top.mas_equalTo(self.view3.bottom).offset(2); make.height.mas_equalTo(height2); }]; [_view1 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.firstView); make.right.mas_equalTo(self.firstView.centerX).offset(-2); make.top.mas_equalTo(self.firstView.top); make.height.mas_equalTo(height); }]; [_view2 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view1.right).offset(2); make.right.mas_equalTo(self.firstView.right).offset(-2); make.top.mas_equalTo(self.firstView.top); make.height.mas_equalTo(height); }]; [_view3 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view1.left); make.right.mas_equalTo(self.view2.right); make.top.mas_equalTo(self.view1.bottom).offset(2); make.height.mas_equalTo(height1); }]; [_view4 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.secondView); make.right.mas_equalTo(self.view1.right); make.top.mas_equalTo(self.secondView.top); make.height.mas_equalTo(height); }]; [_view5 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view4.right).offset(2); make.right.mas_equalTo(self.secondView.right).offset(-2); make.top.mas_equalTo(self.secondView.top); make.height.mas_equalTo(height); }]; [_view6 remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.view4.left); make.right.mas_equalTo(self.view5.right); make.top.mas_equalTo(self.view4.bottom).offset(2); make.height.mas_equalTo(height1); }]; } - (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)gotoImgVC:(listContObjectVO *)bo{ ImageContentController *hotImageVC = [[ImageContentController alloc] init]; hotImageVC.nodeID = bo.contId; hotImageVC.type = imageScanType; [self.navigationController pushViewController:hotImageVC animated:YES]; } /* #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