• TableView和Scrollview的混用


      刚开始做ios,所以很多都不懂,把不会的记下来,可以帮助有需要的人,也可以留下自己学习路上的点滴!!!!

      首先:在一个VC里添加一个ScrollView,然后,在ScrollView里添加3个VC:(TableView、Tableview、ViewController);

      第一步:创建三个不同的VC;

      第二步:在viewcontroller.h里:

          #import "CommunityOneViewController.h"

          #import "CommunityTwoViewController.h"

          #import "CommunityThreeViewController.h"

          @interface MainViewController : BaseViewController<UIScrollViewDelegate>

          //通过视图来定义属性

          @property(nonatomic,strong) CommunityOneViewController *oneTableView;

          @property(nonatomic,strong) CommunityTwoViewController *twoTableView;

          @property(nonatomic,strong) CommunityThreeViewController *threeView;

          //定义滚动视图

          @property(nonatomic,strong) UIScrollView *scroll;

          //定义分页控件

          @property(nonatomic,strong) UIPageControl *page;

      第三步:在viewcontroller.m里:

    - (void)viewDidLoad

    {

        [super viewDidLoad];

     

        self.scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

        _scroll.pagingEnabled=YES;

        _scroll.delegate = self;

        _scroll.bounces=YES;

        [_scroll setBackgroundColor:[UIColor lightGrayColor]];

        self.scroll.contentSize = CGSizeMake(self.view.frame.size.width*3, self.view.frame.size.height);

        

           ////////////////////////////////第一个视图////////////////////////////////////////

     

        _oneTableView = [[CommunityOneViewController alloc]init];

        _oneTableView.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);

           ////////////////////////////////第二个视图////////////////////////////////////////

        

        _twoTableView = [[CommunityTwoViewController alloc]init];

        _twoTableView.view.frame = CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);

           

        ////////////////////////////////第三个视图////////////////////////////////////////

        

        _threeView = [[CommunityThreeViewController alloc]init];

        _threeView.view.frame = CGRectMake(self.view.frame.size.width*2, 0, self.view.frame.size.width, self.view.frame.size.height);

        

        [self.scroll addSubview:_oneTableView.view];

        [self.scroll addSubview:_twoTableView.view];

        [self.scroll addSubview:_threeView.view];

        [self.view addSubview:_scroll];

        self.page = [[UIPageControl alloc]initWithFrame:CGRectMake(150, 360, 10, 25)];

        [self.page setTintColor:[UIColor redColor]];

        _page.numberOfPages=3;

        _page.currentPageIndicatorTintColor=[UIColor greenColor];

        [self.page addTarget:self action:@selector(gotoPage) forControlEvents:UIControlEventValueChanged];

        [self.view addSubview:_page];

    }

    -(void)gotoPage{

        CGRect frame;

        frame.origin.x = self.scroll.frame.size.width * self.page.currentPage;

        frame.origin.y = 0;

        frame.size = self.scroll.frame.size;

        [self.scroll scrollRectToVisible:frame animated:YES];

    }

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

        CGFloat pageWidth = self.scroll.frame.size.width;

        // 在滚动超过页面宽度的50%的时候,切换到新的页面

        // + 1 是因为paged control 是从1开始计数的

        int page = floor((self.scroll.contentOffset.x - pageWidth/2)/pageWidth) + 1;

        self.page.currentPage = page;

    }

     只需要这几步,就可以在一个ScrollView里添加几个不同的视图了,然后就去执行不同的操作就可以了。

  • 相关阅读:
    dell台式机网络唤醒
    今天学习到ROS的PCC的新的一种场景,用PCC不是为了带宽叠加而是为了换IP,PCC的标准做法
    默认ros安装好以后,可能对外开放的端口号,可能被黑客利用的地方,ros的0day漏洞
    ros-winbox利用防火墙安全登录,二次碰撞方法
    S5120V2-IRF2配置
    routeros ros mikrotik的ipsec配置,注意配置的步骤,以及哪些硬件支持哪种加速
    60岁-80岁老年人住院医疗险,既往症可理赔!家有长辈首选
    docker上2分钟安装mikrotik routeros
    pandas filter数据筛选
    (纪录片)光的故事 BBC Light Fantastic (2004)
  • 原文地址:https://www.cnblogs.com/xumei/p/3847360.html
Copyright © 2020-2023  润新知