【代碼筆記】底下滾動,上面標題列也會跟著變動,筆記標題列

來源:互聯網
上載者:User

【代碼筆記】底下滾動,上面標題列也會跟著變動,筆記標題列

一,。

二,工程圖。

三,代碼。

RootViewController.h

#import <UIKit/UIKit.h>#import "SVSegmentedControl.h"@interface RootViewController : UIViewController<UIScrollViewDelegate>{    UIScrollView *scrollView1;    UIScrollView *scrollView2;    UIPageControl *pag;    NSMutableArray *dataArray;    SVSegmentedControl *options;}@end

 

RootViewController.m

#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.        //初始化背景圖    [self initBackGroundView];}#pragma -mark -functions-(void)initBackGroundView{    //隱藏導航條    self.navigationController.navigationBarHidden=YES;        //底部的捲軸    scrollView1=[[UIScrollView alloc]init];    scrollView1.frame=CGRectMake(0, 40, 320, 400);    scrollView1.backgroundColor=[UIColor grayColor];    scrollView1.delegate=self;    scrollView1.pagingEnabled=YES;    scrollView1.contentSize=CGSizeMake(320*2, 376);    [self.view addSubview:scrollView1];        //第一頁的內容    UIView *v1=[[UIView alloc]init];    [v1 setFrame:CGRectMake(0, 0, 320, 376)];    v1.backgroundColor=[UIColor redColor];    [scrollView1 addSubview:v1];        //第二頁的內容    UIView *v2=[[UIView alloc]init];    v2.frame=CGRectMake(320, 0, 320, 376);    v2.backgroundColor=[UIColor blueColor];    [scrollView1 addSubview:v2];        //下面指示頁的圓點    pag=[[UIPageControl alloc]initWithFrame:CGRectMake(160, 400, 0, 0)];    pag.numberOfPages=2;    pag.currentPage=0;    [self.view addSubview:pag];        //上面的滑動表徵圖    options = [[SVSegmentedControl alloc] initWithSectionTitles:[NSArray arrayWithObjects:@"購車應用",@"車主應用", nil]];    [options addTarget:self action:@selector(actiBtClick:) forControlEvents:UIControlEventValueChanged];    [options setBackgroundImage:[UIImage imageNamed:@"switchBg.png"]];    options.center=CGPointMake(160, 50);    options.crossFadeLabelsOnDrag=YES;    options.selectedIndex=0;    options.textColor=[UIColor blackColor];    options.LKWidth=120;    options.textShadowOffset=CGSizeMake(0, 0);    options.textShadowColor=[UIColor clearColor];    options.height=30;    options.thumb.backgroundImage=[UIImage imageNamed:@"按鈕-2.png"];    options.thumb.highlightedBackgroundImage=[UIImage imageNamed:@"按鈕-2.png"];    options.thumb.textShadowColor=[UIColor clearColor];    options.thumb.textShadowOffset=CGSizeMake(0, 0);    [self.view addSubview:options];    }#pragma -mark -doClickActions- (void)actiBtClick:(SVSegmentedControl *)sender{    if(sender.selectedIndex==0)    {        [scrollView1 setContentOffset:CGPointMake(0, scrollView1.contentOffset.y) animated:YES];        pag.currentPage=0;    }    else if(sender.selectedIndex==1)    {        [scrollView1 setContentOffset:CGPointMake(320, scrollView1.contentOffset.y) animated:YES];        pag.currentPage=1;    }}#pragma -mark -scrollViewDelegate-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{    if(scrollView1.contentOffset.x==0)    {        pag.currentPage=0;        [options moveThumbToIndex:0 animate:YES];    }    else if(scrollView1.contentOffset.x==320)    {        pag.currentPage=1;        [options moveThumbToIndex:1 animate:YES];    }}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.