IOS Imitation Hot Topic hot wheel-Seeding interface Tableview_ios

Source: Internet
Author: User
Tags reserved

Nonsense not much to say directly on the code:

This feature should be quite common, a tableview to another tableview, something like segment, which I encapsulated:

VIEWCONTROLLER.M///////Created by elegant scented on 16/6/3. COPYRIGHT©2016 year elegant scented.
All rights reserved. #import "DCNavTabBarController.h" #import "HTMacro.h" @interface Dcnavtabbarcontroller () <uiscrollviewdelegate&
Gt
@property (nonatomic, weak) UIButton *oldbtn;
@property (Nonatomic,strong) Nsarray *vcarr;
@property (nonatomic, weak) Uiscrollview *contentview;
@property (nonatomic, weak) Uiscrollview *topbar;
@property (nonatomic,assign) cgfloat btnw;

@property (nonatomic, weak) UIView *slider; @end @implementation Dcnavtabbarcontroller-(Uicolor *) Slidercolor {if (_slidercolor = = nil) {_slidercolor = [Uicolo
 R colorwithred:1.00 green:0.36 blue:0.25 alpha:1.00];
return _slidercolor; }-(Uicolor *) Btntextnomalcolor {if (_btntextnomalcolor = = nil) {_btntextnomalcolor = [Uicolor colorwithwhite:0.205 A
 LPHA:1.000];
return _btntextnomalcolor; }-(Uicolor *) Btntextseletedcolor {if (_btntextseletedcolor = = nil) {_btntextseletedcolor = [Uicolor colorwithred:1.green:0.36 blue:0.25 alpha:1.00];
return _btntextseletedcolor;
 }-(Uicolor *) Topbarcolor {if (_topbarcolor = = nil) {_topbarcolor = [uicolor Whitecolor];
return _topbarcolor; }-(Instancetype) Initwithsubviewcontrollers: (Nsarray *) subviewcontrollers {if (self = [super init]) {_vcarr = Subview
 controllers;
return self;
 }-(void) viewdidload {[Super viewdidload];
 Add the above navigation bar [self addtopbar];
 Add a child controller [self Addvcview];
Add slider [self addsliderview]; }-(void) Addsliderview {if (self).
 Vcarr.count = = 0) return;
 UIView *slider = [[UIView alloc]initwithframe:cgrectmake (25,41,SELF.BTNW-50, 3)];
 Slider.backgroundcolor = Self.slidercolor;
 [Self.topbar Addsubview:slider];
Self.slider = slider; }-(void) Addtopbar {if (self).
 Vcarr.count = = 0) return; Nsuinteger count = self.
 Vcarr.count;
 Uiscrollview *scrollview = [[Uiscrollview alloc]initwithframe:cgrectmake (0, 0, Screen_width, 44)];
 Scrollview.backgroundcolor = Self.topbarcolor;
 Self.topbar = ScrollView; Self.Topbar.bounces = NO;
 [Self.view AddSubview:self.topBar];
 if (Count <= 5) {self.btnw = Screen_width/count;
 else {self.btnw = screen_width/5.0; }//Add button for (int i = 0; i<count; i++) {Uiviewcontroller *VC = self.
  Vcarr[i];
  UIButton *btn = [[UIButton alloc]initwithframe:cgrectmake (I*SELF.BTNW, 0, SELF.BTNW, 44)];
  Btn.titleLabel.font = [Uifont systemfontofsize:15];
  Btn.titleLabel.numberOfLines = 0;
  Btn.titleLabel.textAlignment = 1;
  Btn.tag = 10000+i;
  [Btn SetTitleColor:self.btnTextNomalColor Forstate:uicontrolstatenormal];
  [Btn SetTitleColor:self.btnTextSeletedColor forstate:uicontrolstateselected];
  [Btn SetTitle:vc.title Forstate:uicontrolstatenormal];
  [Btn addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];
  [Self.topbar ADDSUBVIEW:BTN];
   if (i = = 0) {btn.selected = YES;
  SELF.OLDBTN = BTN;
} self.topBar.contentSize = Cgsizemake (self.btnw *count,-64); }-(void) Addvcview {Uiscrollview *conTentview = [[Uiscrollview alloc]initwithframe:cgrectmake (0, 0+44, Screen_width, screen_height-44)];
 Self.contentview = Contentview;
 Self.contentView.bounces = NO;
 Contentview.delegate = self;
 Contentview.backgroundcolor = [Uicolor colorwithwhite:0.859 alpha:1.000];

 [Self.view Addsubview:contentview]; Nsuinteger count = self.
 Vcarr.count; for (int i=0; i<count; i++) {Uiviewcontroller *VC = self.
  Vcarr[i];
  [Self ADDCHILDVIEWCONTROLLER:VC];
  Vc.view.frame = CGRectMake (i*screen_width, 0, Screen_width, screen_height-44);
 [Contentview AddSubview:vc.view];
 } contentview.contentsize = Cgsizemake (Count*screen_width, screen_height-44);
contentview.pagingenabled = YES;
 }-(void) Click: (UIButton *) Sender {if (sender.selected) return;
 self.oldBtn.selected = NO;
 sender.selected = YES;
  Self.contentView.contentOffset = Cgpointmake ((sender.tag-10000) *screen_width, 0);
 Self.oldBtn.transform = cgaffinetransformidentity;

 SELF.OLDBTN = sender; Determine if the navigation bar needs to be moved CGFloat MaxX= Cgrectgetmaxx (Self.slider.frame); if (MaxX >=screen_width && sender.tag!= self. Vcarr.count + 10000-1) {[UIView animatewithduration:0.3 animations:^{self.topBar.contentOffset = Cgpointmake (max
  X-screen_width + SELF.BTNW,-64);
 }]; }else if (MaxX < screen_width) {UIView animatewithduration:0.3 animations:^{self.topBar.contentOffset = Cgpoint
  Make (0, 0);
 }]; }-(void) Scrollviewdidscroll: (Uiscrollview *) ScrollView {//sliding navigation bar Self.slider.frame = CGRectMake (
Scrollview.contentoffset.x/screen_width *SELF.BTNW +, self.btnw-50, 3); //Decide whether to toggle the state of the navigation bar button-(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView {cgfloat OFFX =
 Scrollview.contentoffset.x;
 int tag = (int) (Offx/screen_width + 0.5) + 10000;
 UIButton *btn = [Self.view Viewwithtag:tag];
 if (tag!= self.oldBtn.tag) {[Self click:btn];

 }}-(void) didreceivememorywarning {[Super didreceivememorywarning];} @end

This is easy to understand, is not, it is not here to explain more.

The one on the top. is to hide the navigation bar, customize a small uiview to intercept the network image as a navigation bar, and customize a large view as a TableView header view. And I also used the Observer Registration message notification, the code is a bit long, but I write a note oh, can understand.

BOOKMARKSVIEWCONTROLLER.M//Hottopic////Created by Dllo on 16/9/7. COPYRIGHT©2016 year elegant scented.
All rights reserved. #import "BookMarksViewController.h" #import "HTMacro.h" #import "Uiview+extension.h" #import "BookTableViewCell.h" Import "EssayViewController.h" #import "SubscriberViewController.h" #import "UMSocial.h" "#import" DCNavTabBarController.h "#import" "Uiimageview+webcache.h" #import "AFNetworking.h" #import "HotTopicsModel.h" #import "TopicModel.h" #import "NodeModel.h" #import "UserModel.h" #import "Source.h" #import "DisposeViewController.h" #import
"HeadImageView.h" static cgfloat const Headviewheight = 280; @interface Bookmarksviewcontroller () <UITableViewDelegate,UITableViewDataSource> @property (nonatomic, strong
) Booktableviewcell * Maintableview; @property (nonatomic, Strong) Headimageview * headimageview;//head picture @property (Nonatomic, Strong) Uiimageview * Avatarimag
E
@property (nonatomic, Strong) Uilabel * Countentlabel; @property (Nonatomic, Strong) Uiimageview *img;
@property (nonatomic, strong) Hottopicsmodel *hottopic;
@property (nonatomic, strong) Uilabel *titlelabel;
@property (nonatomic, assign) BOOL CanScroll;
@property (nonatomic, assign) BOOL Istopiscannotmovetabview;
@property (nonatomic, assign) BOOL Istopiscannotmovetabviewpre;
@property (nonatomic, strong) UIView *barview;

@property (nonatomic, strong) Uilabel *titletext;

@end @implementation Bookmarksviewcontroller @synthesize Maintableview;
 -(void) Viewwillappear: (BOOL) animated {[Super viewwillappear:animated];
[Self.navigationcontroller Setnavigationbarhidden:yes]; }-(void) viewdidload {[Super viewdidload];//This API function is in the Navigationcontroller stack Uiviewcontroller can support the right sliding gesture,
 That is, do not click the Back button in the upper right corner, gently on the left side of the screen slide, the screen will return, as the iOS device screen increases, this small function makes the finger short, thumb and hand-disabled people see the Gospel.
 Self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
 [Self.navigationcontroller Setnavigationbarhidden:yes];
 Self.automaticallyadjustsscrollviewinsets = NO; [Self.view AddSubview:self.mainTableView];
 Set TableView header View Self.mainTableView.tableHeaderView = Self.headimageview; Hide the navigation bar so that it becomes transparent [self.navigationController.navigationBar setbackgroundimage:[uiimage new] Forbarmetrics:
 Uibarmetricsdefault];
 Hide the black line of the navigation bar [Self.navigationController.navigationBar setshadowimage:[uiimage New]]; /** Observer Registration Message * * [[nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (leavetop:) name:@ "Leavetop
 "Object:nil];
[Self creatview];
 The navigation bar is written as a custom view-(void) Creatview {_barview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, Screen_width, 64)];
 UIButton *backbutton = [UIButton buttonwithtype:uibuttontypecustom];
 Backbutton.frame = CGRectMake (10, 30, 30, 30);
 [Backbutton setimage:[uiimage imagenamed:@ "Backbar"] forstate:uicontrolstatenormal];
 [Backbutton addtarget:self Action: @selector (CLICKBACKBTN:) forcontrolevents:uicontroleventtouchupinside];
 UIButton *sharebtn = [UIButton buttonwithtype:uibuttontypecustom]; Sharebtn.frame = CGRectMake (screen_width-50, 30, 30, 30);
 [Sharebtn setimage:[uiimage imagenamed:@ "Sharebar"] forstate:uicontrolstatenormal];
 [Sharebtn addtarget:self Action: @selector (CLICKSHAREBTN:) forcontrolevents:uicontroleventtouchupinside];
 _titletext = [[Uilabel alloc] Initwithframe:cgrectmake (M, screen_width-100, 30)];
 _titletext.text = @ "Favorites";
 _titletext.textalignment = 1;
 _titletext.textcolor = [Uicolor Whitecolor];
 The effect of uiblureffect *blur = [Uiblureffect effectwithstyle:uiblureffectstyleextralight];
 Uivisualeffectview *effectview = [[Uivisualeffectview alloc] initwitheffect:blur];
 Effectview.backgroundcolor = [Uicolor colorwithwhite:0.508 alpha:1.000];
 Effectview.alpha = 0.65;
 Effectview.frame = CGRectMake (0, 0, Screen_width, 64);
 [_barview Addsubview:effectview];
 [_barview Addsubview:backbutton];
 [_barview ADDSUBVIEW:SHAREBTN];
 [_barview Addsubview:_titletext];
[Self.view Addsubview:_barview]; /** * Notificationobserver Observer: Self * Notificationselector method name for processing messages: getuserprofilesuccesS * NOTIFICATIONNAME message notification name: notification_getuserprofilesuccess * Notificationsender message sender: Indicates which sender's notification is received, if the fourth parameter is nil,
 Receive notification of all senders/* (void) Leavetop: (nsnotification *) notification{nsdictionary *userinfo = notification.userinfo;
 NSString *canscroll = userinfo[@ "CanScroll"];
 if ([CanScroll isequaltostring:@ "1"]) {_canscroll = YES;
  /** set the background of the custom view to the background map of the TableView header View/-(UIImage *) Clipimageinoffsety: (cgfloat) y {if (_headimageview.image = = nil) {
 return [UIImage new];
 } CGRect rect = CGRectMake (0, Y, screen_width, 64);
 Cgimageref imageref = Cgimagecreatewithimageinrect ([_headimageview.image cgimage], rect);
 Self.blurView.frame = CGRectMake (0, 0, Screen_width, 64);
 Self.blurView.alpha = 0.7;
 [Self.navigationController.navigationBar Addsubview:_blurview];
 UIImage *thumbscale = [UIImage imagewithcgimage:imageref];
return thumbscale; }///ScrollView offset (void) Scrollviewdidscroll: (Uiscrollview *) scrollview{cgfloat yoffset =
 Scrollview.contentoffset.y; if (YOFfset >= _headimageview.height-64) {yoffset = _headimageview.height-64;
 } uiimage *image = [self clipimageinoffsety:yoffset];
 _barview.backgroundcolor = [Uicolor colorwithpatternimage:image];
 Gets the offset of the scrolling view y-value Self.navigationController.navigationBar.alpha = (headviewheight+yoffset)/(HEADVIEWHEIGHT-64);
 CGFloat taboffsety = [Maintableview rectforsection:0].origin.y-64.0f;
 CGFloat OffsetY = Scrollview.contentoffset.y;
 _istopiscannotmovetabviewpre = _istopiscannotmovetabview;
  if (OffsetY >= taboffsety) {//cannot slide Scrollview.contentoffset = cgpointmake (0, taboffsety);
  _istopiscannotmovetabview = YES;
 _titletext.text = Self.urltitle;
  }else{//can slide _istopiscannotmovetabview = NO;
 _titletext.text = @ "Favorites"; } if (_istopiscannotmovetabview!= _istopiscannotmovetabviewpre) {if (!_istopiscannotmovetabviewpre && _isTopI Scannotmovetabview) {[[Nsnotificationcenter defaultcenter] postnotificationname:@ ' gotop ' Object:nil userInfo:@{@ ' CanScroll ": @" 1 "}];
  _canscroll = NO; } if (_istopiscannotmovetabviewpre &&!_istopiscannotmovetabview) {if (!_canscroll) {Scrollview.contentof
   Fset = Cgpointmake (0, taboffsety); }}}//Header View-(Uiimageview *) Headimageview {if (_headimageview = = nil) {_headimageview = [[Headimageview allo
  C]initwithframe:cgrectmake (0, 0,screen_width,headviewheight)];
  _headimageview.userinteractionenabled = YES; [_headimageview sd_setimagewithurl:[nsurl URLWithString:self.urlHeadImg] placeholderimage:[uiimage imagenamed:@ "
  Touxiang "]completed:^ (uiimage *image, Nserror *error, Sdimagecachetype cachetype, Nsurl *imageURL) {}];
  Uiblureffect *blur = [Uiblureffect effectwithstyle:uiblureffectstyleextralight];
  Uivisualeffectview *effectview = [[Uivisualeffectview alloc] initwitheffect:blur];
  Effectview.backgroundcolor = [Uicolor colorwithwhite:0.508 alpha:1.000];
  Effectview.alpha = 0.7;
  Effectview.frame = CGRectMake (0, 0, screen_width, headviewheight); [_headimageview addsubView:effectview];
  Self.navigationController.hidesBarsOnSwipe = NO;
  _avatarimage = [[Uiimageview alloc] Initwithframe:cgrectmake (+, screen_width/3.3, screen_width/3.3)];
  [_headimageview Addsubview:_avatarimage];
  _avatarimage.userinteractionenabled = YES;
  _avatarimage.layer.maskstobounds = YES; [_avatarimage sd_setimagewithurl:[nsurl URLWithString:self.urlHeadImg] placeholderimage:[uiimage imagenamed:@ "
  Detailviewdefaultmidimage "]]; _countentlabel = [[Uilabel alloc] Initwithframe:cgrectmake (_avatarimage.frame.size.width + +, Screen_width-(SC
  REEN_WIDTH/3 + +), _AVATARIMAGE.FRAME.SIZE.HEIGHT/4)];
  _countentlabel.font = [Uifont systemfontofsize:15];
  _countentlabel.textcolor = [Uicolor Whitecolor];
  _countentlabel.linebreakmode = nslinebreakbywordwrapping;
  _countentlabel.numberoflines = 0;
  _countentlabel.text = Self.urltitle;

  [_headimageview Addsubview:_countentlabel]; _img = [[Uiimageview alloc] Initwithframe:cgrectmake (_countentlabel.frame.origin.x, _countentlabel.frame.size.height + _AVATARIMAGE.FRAME.ORIGIN.Y + 10, 30, 30)];
  _img.layer.cornerradius = 15;
  _img.layer.maskstobounds = YES;
  _img.backgroundcolor = [Uicolor Yellowcolor];
  [_headimageview addsubview:_img]; _titlelabel = [[Uilabel alloc] Initwithframe:cgrectmake (_img.frame.size.width + _img.frame.origin.x + 5, _
  IMG.FRAME.ORIGIN.Y, screen_width/1.9, 30)];
  _titlelabel.textcolor = [Uicolor Whitecolor];
  _titlelabel.linebreakmode = nslinebreakbywordwrapping;
  _titlelabel.numberoflines = 0;
  _titlelabel.font = [Uifont systemfontofsize:12];
  [_headimageview Addsubview:_titlelabel]; Uilabel *contextlabel = [[Uilabel alloc] Initwithframe:cgrectmake (_img.frame.origin.x, _IMG.FRAME.ORIGIN.Y + _
  Img.frame.size.height + 6, SCREEN_WIDTH/2, SCREEN_WIDTH/8)];
  Contextlabel.textcolor = [Uicolor Whitecolor];
  Contextlabel.text = Self.urlcontect;
  Contextlabel.linebreakmode = nslinebreakbywordwrapping;
  Contextlabel.numberoflines = 0;Contextlabel.font = [Uifont systemfontofsize:12];
  [_headimageview Addsubview:contextlabel];
  UIButton *takebtn = [UIButton Buttonwithtype:uibuttontypesystem]; Takebtn.frame = CGRectMake (_img.frame.origin.x-20, contextLabel.frame.size.height + CONTEXTLABEL.FRAME.ORIGIN.Y + 10,
  SCREEN_WIDTH/4, _avatarimage.frame.size.height/3.2);
  [takebtn settitle:@ "+ Subscribe to" forstate:uicontrolstatenormal];
  [Takebtn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
  Takebtn.backgroundcolor = [Uicolor colorwithred:1.00 green:0.36 blue:0.25 alpha:1.00];
  TakeBtn.titleLabel.font = [Uifont systemfontofsize:14];
  TakeBtn.layer.cornerRadius = 10;
  [_headimageview ADDSUBVIEW:TAKEBTN];
  UIButton *contributebtn = [UIButton Buttonwithtype:uibuttontypesystem]; Contributebtn.frame = CGRectMake (takebtn.frame.origin.x + takeBtn.frame.size.width + 5, ContextLabel.frame.size.height + contextlabel.frame.origin.y + SCREEN_WIDTH/8, _avatarimage.frame.size.height/
  3.2); [ContribuTEBTN settitle:@ "Submission" forstate:uicontrolstatenormal];
  [Contributebtn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
  ContributeBtn.layer.borderWidth = 1.0;
  ContributeBtn.titleLabel.font = [Uifont systemfontofsize:14]; ContributeBtn.layer.borderColor = [Uicolor Whitecolor].
  Cgcolor;
  ContributeBtn.layer.cornerRadius = 5;
  [_headimageview ADDSUBVIEW:CONTRIBUTEBTN]; UIButton *managelabel = [[UIButton alloc] Initwithframe:cgrectmake (contributeBtn.frame.size.width +
  contributebtn.frame.origin.x, CONTRIBUTEBTN.FRAME.ORIGIN.Y + 5, SCREEN_WIDTH/5, 30)];
  [Managelabel Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];
  [Managelabel settitle:@ "0 not processed ☞" forstate:uicontrolstatenormal];
  manageLabel.titleLabel.textAlignment = 0;
  ManageLabel.titleLabel.font = [Uifont systemfontofsize:12];
  [Managelabel addtarget:self Action: @selector (CLICKMANAGEBTN:) forcontrolevents:uicontroleventtouchupinside];

 [_headimageview Addsubview:managelabel]; } RetuRN _headimageview; }//Large TableView-(UITableView *) Maintableview {if (Maintableview = = nil) {maintableview= [[Booktableviewcell Alloc]i
  Nitwithframe:cgrectmake (0, 0, screen_width,screen_height)];
  Maintableview.delegate = self;
  maintableview.datasource=self;
  Maintableview.bounces = NO;
  Maintableview.separatorstyle = Uitableviewcellseparatorstylenone;
  Maintableview.showsverticalscrollindicator = NO;
  Maintableview.backgroundcolor = [Uicolor Clearcolor];
 Maintableview.rowheight = Screen_height;
return maintableview; } #pragma marl-tabledelegate-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;}-(NSIntege R) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{return 1;}-(CGFloat) TableView: ( UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return screen_height;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{UITableViewCellll = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil];
 Cell.selectionstyle = Uitableviewcellselectionstylenone;
 Add PageView [Cell.contentview addSubview:self.setPageViewControllers];
return cell;
 //Call two small VC-(UIView *) setpageviewcontrollers{Essayviewcontroller *essay = [[Essayviewcontroller alloc] init];
 Essay.urlstr = Self.urlstr;
 Essay.title = [NSString stringwithformat:@ "article \n%@", Self.articlecount];
 Subscriberviewcontroller *subscribe = [[Subscriberviewcontroller alloc] init];
 Subscribe.urlstr = Self.urlstr;
 Subscribe.title = [NSString stringwithformat:@ "subscriber \n%@", Self.subscribercount];
 Nsarray *subviewcontrollers=@[essay, subscribe];
 Dcnavtabbarcontroller *TABBARVC = [[Dcnavtabbarcontroller alloc]initwithsubviewcontrollers:subviewcontrollers];
 TabBarVC.view.frame = CGRectMake (0, 0, screen_width, screen_height);
 [Self.view AddSubview:tabBarVC.view];
 [Self ADDCHILDVIEWCONTROLLER:TABBARVC];
return tabbarvc.view;

 } @end

Write here, it's done, let's look at the results below!

is not particularly good, like to try it!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.