亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

iOS仿網易新聞滾動導航條效果

2019-10-21 18:41:05
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS滾動導航條效果展示的具體代碼,供大家參考,具體內容如下

實現效果

效果:選擇不同的欄目,下面出現不同的視圖,欄目條可以滾動;下面的視圖也可以滾動,滾動時上面對應的欄目要選中顏色為紅色;

滾動的導航條包括兩部分:標題滾動視圖(UIScrollView),內容滾動視圖(UIScrollView)

iOS,滾動,導航條

實現代碼

1.首先實現Main.storyboard

iOS,滾動,導航條

2.創建多個子控制器:頭條、科技、汽車、體育、視頻、圖片、熱點

// 頭條ViewController, 其它控制器和這個控制器都一樣,只是背景顏色不同而已#import <UIKit/UIKit.h>@interface TopLineViewController : UIViewController@end//----------------------------------------------------------------#import "TopLineViewController.h"@interface TopLineViewController ()@end@implementation TopLineViewController- (void)viewDidLoad {  [super viewDidLoad];  self.view.backgroundColor = [UIColor blackColor];}@end

實現Main.storyboard對應的視圖控制器ViewController

#import <UIKit/UIKit.h>@interface ViewController : UIViewController@end//----------------------------------------------------------------#import "ViewController.h"#import "TopLineViewController.h"#import "TechnologyViewController.h"#import "CarViewController.h"#import "SportsViewController.h"#import "VideoViewController.h"#import "ImageViewController.h"#import "HotViewController.h"#define ScreenWidth [UIScreen mainScreen].bounds.size.width#define ScreenHeight [UIScreen mainScreen].bounds.size.height@interface ViewController () <UIScrollViewDelegate>@property (weak, nonatomic) IBOutlet UIScrollView *titleScrollView;@property (weak, nonatomic) IBOutlet UIScrollView *contentScrollView;@property (strong, nonatomic) NSMutableArray *buttons;@property (strong, nonatomic) UIButton *selectedButton;@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];  self.navigationItem.title = @"網易新聞";  // 1. 初始化標題滾動視圖上的按鈕  [self initButtonsForButtonScrollView];}- (void) initButtonsForButtonScrollView {  // 初始化子控制器  [self initChildViewControllers];  CGFloat buttonWidth = 100;  CGFloat buttonHeight = 40;  NSInteger childViewControllerCount = self.childViewControllers.count;  for (NSInteger i = 0; i < childViewControllerCount; i++) {    UIViewController *childViewController = self.childViewControllers[i];    UIButton *titleButton = [UIButton buttonWithType:UIButtonTypeCustom];    titleButton.tag = i;    CGFloat x = i * buttonWidth;    titleButton.frame = CGRectMake(x, 0, buttonWidth, buttonHeight);    [titleButton setTitle:childViewController.title forState:UIControlStateNormal];    [titleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];    [titleButton addTarget:self action:@selector(titleButtonOnClick:) forControlEvents:UIControlEventTouchUpInside];    [self.titleScrollView addSubview:titleButton];    [self.buttons addObject:titleButton];  }  self.titleScrollView.contentSize = CGSizeMake(buttonWidth * childViewControllerCount, 0);  self.titleScrollView.showsHorizontalScrollIndicator = NO;  self.titleScrollView.bounces = NO;  self.contentScrollView.contentSize = CGSizeMake(ScreenWidth * childViewControllerCount, 0);  self.contentScrollView.showsHorizontalScrollIndicator = NO;  self.contentScrollView.pagingEnabled = YES;  self.contentScrollView.delegate = self;  // 禁止額外滾動區域  self.automaticallyAdjustsScrollViewInsets = NO;  // 初始化時默認選中第一個  [self titleButtonOnClick:self.buttons[0]];}- (void)titleButtonOnClick:(UIButton *)button {  // 1. 選中按鈕  [self selectingButton:button];  // 2. 顯示子視圖  [self addViewToContentScrollView:button];}- (void)selectingButton:(UIButton *)button {  [_selectedButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  _selectedButton.transform = CGAffineTransformMakeScale(1.0, 1.0);  [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];  button.transform = CGAffineTransformMakeScale(1.3, 1.3); // 選中字體變大,按鈕變大,字體也跟著變大  _selectedButton = button;  // 選中按鈕時要讓選中的按鈕居中  CGFloat offsetX = button.frame.origin.x - ScreenWidth * 0.5;  CGFloat maxOffsetX = self.titleScrollView.contentSize.width - ScreenWidth;  if (offsetX < 0) {    offsetX = 0;  } else if (offsetX > maxOffsetX) {    offsetX = maxOffsetX;  }  [self.titleScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];}- (void)addViewToContentScrollView:(UIButton *)button {  NSInteger i = button.tag;  UIViewController *childViewController = self.childViewControllers[i];  CGFloat x = i * ScreenWidth;  // 防止添加多次  if (childViewController.view.subviews != nil) {    childViewController.view.frame = CGRectMake(x, 0, ScreenWidth, ScreenHeight);    [self.contentScrollView addSubview:childViewController.view];  }  self.contentScrollView.contentOffset = CGPointMake(x, 0);}#pragma mark - UIScrollViewDelegate- (void)scrollViewDidScroll:(UIScrollView *)scrollView {}// 滾動結束時,將對應的視圖控制器的視圖添加到內容滾動視圖中- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {  NSInteger i = self.contentScrollView.contentOffset.x / ScreenWidth;  [self addViewToContentScrollView:_buttons[i]];  // 內容滾動視圖結束后選中對應的標題按鈕  [self selectingButton:_buttons[i]];}- (void)initChildViewControllers {  // 0.頭條  TopLineViewController * topViewController = [[TopLineViewController alloc] init];  topViewController.title = @"頭條";  [self addChildViewController:topViewController];  // 1.科技  TechnologyViewController * technologyViewController = [[TechnologyViewController alloc] init];  technologyViewController.title = @"科技";  [self addChildViewController:technologyViewController];  // 2.汽車  CarViewController * carViewController = [[CarViewController alloc] init];  carViewController.title = @"汽車";  [self addChildViewController:carViewController];  // 3.體育  SportsViewController * sportsViewController = [[SportsViewController alloc] init];  sportsViewController.title = @"體育";  [self addChildViewController:sportsViewController];  // 4.視頻  VideoViewController * videoViewController = [[VideoViewController alloc] init];  videoViewController.title = @"視頻";  [self addChildViewController:videoViewController];  // 5.圖片  ImageViewController * imageViewController = [[ImageViewController alloc] init];  imageViewController.title = @"圖片";  [self addChildViewController:imageViewController];  // 6.熱點  HotViewController * hotViewController = [[HotViewController alloc] init];  hotViewController.title = @"熱點";  [self addChildViewController:hotViewController];}- (NSMutableArray *)buttons {  if (_buttons == nil) {    _buttons = [NSMutableArray array];  }  return _buttons;}@end

以上代碼即可實現網易新聞 滾動的導航條, 因該功能可能在其它地方使用,所以最好可以將該功能抽出來,便于其它控制器集成,暫時還沒做。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
欧美视频二区36p| 中文字幕自拍vr一区二区三区| 久久视频免费观看| 精品无人区太爽高潮在线播放| 国产精品成av人在线视午夜片| 亚洲第一色中文字幕| 超碰精品一区二区三区乱码| 亚洲的天堂在线中文字幕| 国产精品免费电影| 午夜精品一区二区三区在线视| 成人国产精品色哟哟| 日韩免费看的电影电视剧大全| 亚洲一区二区三区四区在线播放| 2024亚洲男人天堂| 国产精品96久久久久久| 亚洲伊人久久大香线蕉av| www.美女亚洲精品| 久久综合亚洲社区| 日韩在线播放视频| 日韩av理论片| 午夜精品久久久久久久久久久久久| 亚洲午夜性刺激影院| 欧美在线视频一区| 亚洲理论在线a中文字幕| 久久免费少妇高潮久久精品99| 欧美中文字幕在线播放| 欧美另类老女人| 国产成人激情小视频| 国产精品xxx视频| 亚洲美女av电影| 欧美乱大交xxxxx另类电影| 欧美刺激性大交免费视频| 中文欧美在线视频| 91av福利视频| 国产精品h片在线播放| 国产精品成人观看视频国产奇米| 久久精品小视频| 久久久国产精彩视频美女艺术照福利| 亚洲免费精彩视频| 久久久电影免费观看完整版| 国产精品欧美激情在线播放| 欧美日韩中文字幕| 欧美综合第一页| 欧美激情视频在线| 日韩中文在线观看| 韩国v欧美v日本v亚洲| 久久亚洲国产精品成人av秋霞| 欧美日韩国产va另类| 亚洲国产精品va在线| 国产成人小视频在线观看| 久久久999国产精品| 国产成人精品久久亚洲高清不卡| 自拍偷拍亚洲精品| 深夜福利日韩在线看| 久久夜精品va视频免费观看| 亚洲人成啪啪网站| 国产一区二区三区在线播放免费观看| 97免费中文视频在线观看| 91高潮在线观看| 日韩一区二区精品视频| 亲爱的老师9免费观看全集电视剧| 91网站在线看| 亚洲人成绝费网站色www| 欧美日本亚洲视频| 欧美日韩国产丝袜另类| 欧美日韩加勒比精品一区| 国产精品成人久久久久| 日韩视频在线免费观看| 国产精品第三页| 国产亚洲欧洲在线| 亚洲免费影视第一页| 另类图片亚洲另类| 国产aⅴ夜夜欢一区二区三区| 国产精品久久久久久网站| 成人av.网址在线网站| 久久成人这里只有精品| 久久久久99精品久久久久| 欧美另类老女人| 亚洲热线99精品视频| 91日本在线视频| 国产乱肥老妇国产一区二| yw.139尤物在线精品视频| 亚洲综合精品一区二区| 国产精品91久久久| 久久视频在线直播| 日韩欧美黄色动漫| 91久久嫩草影院一区二区| 日韩高清人体午夜| 国产精品美女久久久久av超清| 欧美猛交免费看| 粉嫩av一区二区三区免费野| 日韩av最新在线观看| 精品久久久久久中文字幕一区奶水| 久久久久久久久国产| 久久国产精彩视频| 日韩av日韩在线观看| 亚洲成人网在线观看| 97在线看免费观看视频在线观看| 成人免费网站在线看| 精品国产一区二区三区久久| 亚洲bt欧美bt日本bt| 欧美亚洲视频在线观看| 九九热最新视频//这里只有精品| 国产拍精品一二三| 日韩在线播放视频| 91丝袜美腿美女视频网站| 久久综合伊人77777| 成人妇女免费播放久久久| 92裸体在线视频网站| 亚洲性无码av在线| 日产日韩在线亚洲欧美| 亚洲成色999久久网站| 日韩av在线一区二区| 欧美国产中文字幕| 国产经典一区二区| 久久色精品视频| 国产精品久久久久999| 精品成人国产在线观看男人呻吟| 亚洲影院色在线观看免费| 亚洲天堂影视av| 亚洲美女精品成人在线视频| 国产日韩欧美中文| 国模精品视频一区二区| 成人久久久久久| 一区二区在线视频| 中文字幕亚洲天堂| 亚洲欧美色婷婷| 日韩经典一区二区三区| 色诱女教师一区二区三区| 欧美精品在线观看| 欧美大码xxxx| 在线精品国产欧美| 久热精品视频在线观看| 国产亚洲精品综合一区91| 美女国内精品自产拍在线播放| 欧美电影在线观看网站| 国产精品亚洲综合天堂夜夜| 91中文在线视频| 国产精品国产三级国产aⅴ浪潮| 91sao在线观看国产| 日韩中文av在线| 欧美人与性动交| 国产精品男女猛烈高潮激情| 亚洲精品电影久久久| 亚洲国产精品va在线| 69av在线播放| 欧美性猛交xxxx乱大交极品| 色午夜这里只有精品| 91爱视频在线| 亚洲国产精品va在线| 亚洲精品www久久久久久广东| 国产极品精品在线观看| 欧美久久精品午夜青青大伊人| 欧美第一页在线| 亚洲丁香久久久| 久久人人看视频| 国产欧美婷婷中文| 久久精品国产亚洲精品2020| 欧美性videos高清精品| 永久免费看mv网站入口亚洲| 欧美大肥婆大肥bbbbb| 久久久女人电视剧免费播放下载| 国产精品日本精品| 成人午夜在线影院|