IOS开发学习日记(三)

UIScrollView

        contentOffset 滚动区域左上角与视图左上角的距离

        frame 视图在屏幕中展示的大小

        contentSize 视图内部,内容可以滚动的区域

其他常用属性和方法

        scrollEnabled

        pagingEnabled

        showHorizontalScrollIndicator

        setContentOffset:animated

-(instancetype)init{
    self = [super init];
    if(self){
        self.view.backgroundColor = [UIColor lightGrayColor];
        self.tabBarItem.title = @"推荐";
        self.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/like@2x.png"];
        self.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/like_selected@2x.png"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    scrollView.backgroundColor = [UIColor lightGrayColor];
    scrollView.contentSize = CGSizeMake(self.view.bounds.size.width * 5, self.view.bounds.size.height);
    scrollView.showsHorizontalScrollIndicator = NO;    //是否显示横向滚动条
    scrollView.pagingEnabled = YES;    // 是否支持翻页效果
    NSArray *colorArray = @[[UIColor redColor], [UIColor blueColor], [UIColor grayColor],[UIColor greenColor], [UIColor yellowColor] ];
    for(int i = 0;i < 5;i++){
        UIView *view = [[UIView alloc] initWithFrame:(CGRectMake(scrollView.bounds.size.width * i,
                                                                 0, scrollView.bounds.size.width,
                                                                 scrollView.bounds.size.height))];
        view.backgroundColor = [colorArray objectAtIndex:i];
        [scrollView addSubview:view];
    }
    [self.view addSubview:scrollView];
}

 常用UIScrollViewDelegate:


// 用于监听页面滚动,根据Offset做业务逻辑
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;   

// 页面拖拽,用于中断业务逻辑                                            
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
// called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset API_AVAILABLE(ios(5.0));
// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;

// 页面减速,页面停止时开始逻辑,如视频自动播放
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;   // called on finger up as we are moving
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;      // called when scroll view grinds to a halt

UIKit中的滚动视图

UIView(渲染绘制/子视图管理)——> UIScrollView(滚动功能)——>                                                                                                                         UITableView/UICollectionView(子视图布局/复用)

UIScrollViewDelegate(滚动相关回调)——> UICollectionViewDelegate/UITableVieDelegate(基于滚动,视图相关回调)

        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我真的学不会了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值