信息管理

//? AppDelegate.m


#import "NextViewController.h"

#import "ViewController.h"


//? ViewController.m

#import "NextViewController.h"

導(dǎo)入頭文件

<UIScrollViewDelegat>

{

UIScrollView * _scollView;

}

//=======================================

_scollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self .view.frame))];

_scollView.backgroundColor = [UIColor blackColor];

[self.view addSubview:_scollView];

#pragma mark - 利用for循環(huán)來添加圖片

for (int i = 0; i < 3; i ++) {

UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i*CGRectGetWidth(_scollView.frame), 0, CGRectGetWidth(_scollView.frame), CGRectGetHeight(_scollView.frame))];

[imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]]];

imageView.contentMode = UIViewContentModeScaleAspectFit;//設(shè)置圖片視圖的內(nèi)容顯示(這里設(shè)置為適合本身長寬比例)

imageView.clipsToBounds = YES;//把超出父視圖的部分剪切掉

[_scollView addSubview:imageView];

}

#pragma mark - 配置滾動視圖

[_scollView setContentSize:CGSizeMake(CGRectGetWidth(_scollView.frame)*3, CGRectGetHeight(_scollView.frame))]; //設(shè)置內(nèi)容大小(能滾動的最大范圍)

//? ? //設(shè)置偏移量

//? ? [_scollView setContentOffset:CGPointMake(1400, 50)];

//設(shè)置指示器

_scollView.showsHorizontalScrollIndicator = NO;//水平方向的指示器

_scollView.showsVerticalScrollIndicator = NO; //垂直方向的指示器

//設(shè)置按頁滾動

_scollView.pagingEnabled = YES;

//設(shè)置滾動到邊界的回彈效果

_scollView.bounces = YES;

_scollView.delegate = self;

#pragma mark - UIPageControl

UIPageControl * pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(150, 650, 100, 40)];//他的大小影響用戶交互的范圍

//? ? pageControl.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetWidth(self.view.bounds)+60);

pageControl.currentPage = 0;

pageControl.numberOfPages = 3;

pageControl.currentPageIndicatorTintColor = [UIColor orangeColor];//頁面控制器當(dāng)前頁面時的指示器的顏色

pageControl.pageIndicatorTintColor = [UIColor grayColor];

//? pageControl.currentPage = //該方法去scrollViewDidEndDecelerating里面寫

pageControl.tag = 101;

//? ? pageControl.backgroundColor = [UIColor grayColor];

[pageControl addTarget:self action:@selector(pressedGR:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:pageControl];

}

//=============================================

- (void)viewDidAppear:(BOOL)animated{? ? [super viewDidAppear:animated];? ? //設(shè)置偏移量? ? [_scollView setContentOffset:CGPointMake(0, 0) animated:YES];}- (void)pressedGR:(UIPageControl *)sender{? ? [_scollView setContentOffset:CGPointMake(sender.currentPage * CGRectGetWidth(_scollView.frame), 0) animated:YES];? ? }#pragma mark -//滾動視圖滾動的時候被調(diào)用

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

//檢測視圖偏移量

NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));

if (scrollView.contentOffset.x == 828)

{

UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];

// 設(shè)置位置

btn.frame = CGRectMake(150, 600, 100, 40);

// 添加標(biāo)題

[btn setTitle:@"立即進入" forState:UIControlStateNormal];

// 設(shè)置背景顏色

btn.backgroundColor = [UIColor yellowColor];

// 設(shè)置字體顏色

[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

// 添加按鈕事件

[btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:btn];

}

}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

{

NSLog(@"將要開始拖動");

}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

{

NSLog(@"結(jié)束拖動");

}

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

{

NSLog(@"開始減速");

}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

{

int index = scrollView.contentOffset.x/CGRectGetWidth(scrollView.frame);

UIView * view = [self.view viewWithTag:101];

if ([view isKindOfClass:[UIPageControl class]]) {

UIPageControl* pagecontrol = (UIPageControl *)view;//強轉(zhuǎn)為UIPageControl

pagecontrol.currentPage = index;

}

NSLog(@"減速完畢");

}

- (void)click

{

NextViewController *next = [[NextViewController alloc]init];

[self presentViewController:next animated:YES completion:nil];

}




////? NextViewController.m

<UITableViewDelegate,UITableViewDataSource>

{

UINavigationBar *_navigationBar;

UITableView *_rightTableView;

UITableView *_leftTableView;

NSArray *_leftTableSource;

NSArray *_rightTableSource;

}


//]===============

// 設(shè)置背景顏色

self.view.backgroundColor = [UIColor lightGrayColor];

[self buildNavBar];

//先生成存放標(biāo)題的數(shù)據(jù)

NSArray *array = [NSArray arrayWithObjects:@"分類",@"排行",@"歌手",@"電臺",@"兒歌",@"MV",@"三" ,nil];

//初始化UISegmentedControl

UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];

//設(shè)置frame

segment.frame = CGRectMake(0, 64, self.view.frame.size.width, 44);

[self.view addSubview:segment];

_leftTableSource = @[@"推薦",@"心情",@"主題",@"人群",@"場景",@"曲風(fēng)",@"語種",@"樂器",@"歌手"];

_rightTableSource = @[@{@"header":@"推薦",@"title":@[@"aa",@"bb",@"cc",@"dd",@"ee",@"ff"]},

@{@"header":@"心情",@"title":@[@"gg",@"mm",@"nn",@"oo",@"pp",@"qq"]},

@{@"header":@"主題",@"title":@[@"rr",@"ss",@"jj",@"xx",@"yy",@"zz"]},

@{@"header":@"人群",@"title":@[@"aa",@"bb",@"cc",@"dd",@"ee",@"ff"]},

@{@"header":@"場景",@"title":@[@"gg",@"mm",@"nn",@"oo",@"pp",@"qq"]},

@{@"header":@"曲風(fēng)",@"title":@[@"rr",@"ss",@"jj",@"xx",@"yy",@"zz"]},? ? ? ? ? ? ? ? ? ? ? ? ? @{@"header":@"語種",@"title":@[@"rr",@"ss",@"jj",@"xx",@"yy",@"zz"]},? ? ? ? ? ? ? ? ? ? ? ? ? @{@"header":@"樂器",@"title":@[@"rr",@"ss",@"jj",@"xx",@"yy",@"zz"]},? ? ? ? ? ? ? ? ? ? ? ? ? @{@"header":@"歌手",@"title":@[@"rr",@"ss",@"jj",@"xx",@"yy",@"zz"]}];

[self setupSomeParamars];


//==============

// 創(chuàng)建兩個tableview

- (void)setupSomeParamars

{

_rightTableView = [[UITableView alloc] initWithFrame:CGRectMake(100, 108, self.view.frame.size.width - 100, self.view.frame.size.height-44) style:UITableViewStyleGrouped];

_rightTableView.dataSource = self;

_rightTableView.delegate = self;

[self.view addSubview:_rightTableView];

_leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 108, 100, self.view.frame.size.height-44) style:UITableViewStyleGrouped];

_leftTableView.dataSource = self;

_leftTableView.delegate = self;

[self.view addSubview:_leftTableView];

// 創(chuàng)建底部欄

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-44, [UIScreen mainScreen].bounds.size.width, 44)];

view.backgroundColor = [UIColor redColor];

UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];

img.image = [UIImage imageNamed:@"1.jpg"];

[view addSubview:img];

UILabel *l1 = [[UILabel alloc]initWithFrame:CGRectMake(50, 5, 70, 20)];

l1.text = @"凸凹";

[view addSubview:l1];

UILabel *l2 = [[UILabel alloc]initWithFrame:CGRectMake(50, 25, 70, 20)];

l2.text = @"崔長春";

[view addSubview:l2];

UILabel *l3 = [[UILabel alloc]initWithFrame:CGRectMake(250, 5, 40, 40)];

l3.text = @"播放";

[view addSubview:l3];

UILabel *l4 = [[UILabel alloc]initWithFrame:CGRectMake(300, 5, 70, 40)];

l4.text = @"下一首";

[view addSubview:l4];

UILabel *l5 = [[UILabel alloc]initWithFrame:CGRectMake(370, 5, 40, 40)];

l5.text = @"列表";

[view addSubview:l5];

[self.view addSubview:view];

}

// 設(shè)置cell的顯示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *reuseIdentifer = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifer];

if(!cell){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifer];

}

if(tableView == _rightTableView){

cell.textLabel.text = [_rightTableSource[indexPath.section] objectForKey:@"title"][indexPath.row];

cell.imageView.image = [UIImage imageNamed:@"2.jpg"];

cell.detailTextLabel.text = @"522.77萬人在聽";

}else if (tableView == _leftTableView){

cell.textLabel.text = _leftTableSource[indexPath.row];

}

return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

if (tableView == _rightTableView) {

return 50;

}else{

return 50;

}

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

if (tableView == _rightTableView) {

return _rightTableSource.count;

}else{

return 1;

}

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

if (tableView == _leftTableView) {

return _leftTableSource.count;

}else{

return [[_rightTableSource[section] objectForKey:@"title"] count];

}

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

if (tableView == _rightTableView) {

return [_rightTableSource[section] objectForKey:@"header"];

}else{

return nil;

}

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

if(tableView == _rightTableView){

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-100, 40)];

label.backgroundColor = [UIColor cyanColor];

label.text = [_rightTableSource[section] objectForKey:@"header"];

label.textColor = [UIColor redColor];

return label;

}else{

return nil;

}

}

// 聯(lián)動效果在于這里

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

{

if(tableView == _rightTableView){

[_leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:section inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];

}

}

-(void)buildNavBar{

self.view.backgroundColor = [UIColor whiteColor];

[self.view addSubview: self.navigationBar];

}

/**

*? navigation bar

*/

-(UINavigationBar *)navigationBar{

if (!_navigationBar) {

if (self.navigationController) {

// 隱藏原有nav bar

[self.navigationController setNavigationBarHidden:true animated:true];

}

CGRect frame = self.view.bounds;

frame.size.height = 64; //可任意設(shè)置frame

UINavigationBar *bar = [[UINavigationBar alloc] initWithFrame:frame];

bar.barStyle = UIBarStyleDefault;

bar.translucent = false;

bar.autoresizingMask = UIViewAutoresizingFlexibleWidth;

bar.barTintColor = [UIColor redColor];

bar.tintColor = [UIColor whiteColor];

bar.titleTextAttributes = @{ NSForegroundColorAttributeName: [UIColor whiteColor] };

// bar button items? navBarButtonItemDidClick

UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"3"] style:UIBarButtonItemStylePlain target:self action:@selector(navBarButtonItemDidClick:)];

//? ? ? ? cancelItem.tag = NavBarItemCancel;

UIBarButtonItem *okItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"4"] style:UIBarButtonItemStylePlain target:self action:@selector(navBarButtonItemDidClick:)];

//? ? ? ? okItem.tag = NavBarItemOk;

//先生成存放標(biāo)題的數(shù)據(jù)

NSArray *array = [NSArray arrayWithObjects:@"我的",@"樂庫",@"聽歌" ,nil];

//初始化UISegmentedControl

UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];

//設(shè)置frame

segment.frame = CGRectMake(50, 0, self.view.frame.size.width, 30);

// nav item

UINavigationItem *navItem = [[UINavigationItem alloc] init];

navItem.titleView = segment;

navItem.leftBarButtonItem = cancelItem;

navItem.rightBarButtonItem = okItem;

[bar pushNavigationItem:navItem animated:false];

_navigationBar = bar;

}

return _navigationBar;

}



最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末观谦,一起剝皮案震驚了整個濱河市哑子,隨后出現(xiàn)的幾起案子而线,更是在濱河造成了極大的恐慌,老刑警劉巖夜涕,帶你破解...
    沈念sama閱讀 223,126評論 6 520
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異恩商,居然都是意外死亡尤蒿,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,421評論 3 400
  • 文/潘曉璐 我一進店門萍嬉,熙熙樓的掌柜王于貴愁眉苦臉地迎上來乌昔,“玉大人,你說我怎么就攤上這事壤追】牡溃” “怎么了?”我有些...
    開封第一講書人閱讀 169,941評論 0 366
  • 文/不壞的土叔 我叫張陵行冰,是天一觀的道長捅厂。 經(jīng)常有香客問我,道長资柔,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,294評論 1 300
  • 正文 為了忘掉前任撵割,我火速辦了婚禮贿堰,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘啡彬。我一直安慰自己羹与,他們只是感情好故硅,可當(dāng)我...
    茶點故事閱讀 69,295評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著纵搁,像睡著了一般吃衅。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上腾誉,一...
    開封第一講書人閱讀 52,874評論 1 314
  • 那天徘层,我揣著相機與錄音,去河邊找鬼利职。 笑死趣效,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的猪贪。 我是一名探鬼主播跷敬,決...
    沈念sama閱讀 41,285評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼热押!你這毒婦竟也來了西傀?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,249評論 0 277
  • 序言:老撾萬榮一對情侶失蹤桶癣,失蹤者是張志新(化名)和其女友劉穎拥褂,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體鬼廓,經(jīng)...
    沈念sama閱讀 46,760評論 1 321
  • 正文 獨居荒郊野嶺守林人離奇死亡肿仑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,840評論 3 343
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了碎税。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片尤慰。...
    茶點故事閱讀 40,973評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖雷蹂,靈堂內(nèi)的尸體忽然破棺而出伟端,到底是詐尸還是另有隱情,我是刑警寧澤匪煌,帶...
    沈念sama閱讀 36,631評論 5 351
  • 正文 年R本政府宣布责蝠,位于F島的核電站,受9級特大地震影響萎庭,放射性物質(zhì)發(fā)生泄漏霜医。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,315評論 3 336
  • 文/蒙蒙 一驳规、第九天 我趴在偏房一處隱蔽的房頂上張望肴敛。 院中可真熱鬧,春花似錦、人聲如沸医男。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,797評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽镀梭。三九已至刀森,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間报账,已是汗流浹背研底。 一陣腳步聲響...
    開封第一講書人閱讀 33,926評論 1 275
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留笙什,地道東北人飘哨。 一個月前我還...
    沈念sama閱讀 49,431評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像琐凭,于是被迫代替她去往敵國和親芽隆。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,982評論 2 361

推薦閱讀更多精彩內(nèi)容