设为首页 加入收藏

TOP

你真的了解UIScrollView吗?(三)
2017-10-13 09:46:26 】 浏览:7727
Tags:真的 了解 UIScrollView
]]; imageView.frame
= CGRectMake(CGRectGetWidth(self.view.frame)*i, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)); [scrollView addSubview:imageView]; [scrollView addSubview:label]; } //--设置分页效果 scrollView.pagingEnabled = YES; //--设置横向滚动条是否显示 默认值为YES scrollView.showsHorizontalScrollIndicator = YES; //----------------------设置滚动条样式 //--设置边界是否有反弹效果 默认值为YES scrollView.bounces = NO; //---设置代理 scrollView.delegate = self; } #pragma mark -- 滚动视图的代理方法 //将要开始拖拽(手指触碰到屏幕,并且移动) - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{ NSLog(@"---%s", __func__); } //已经开始滚动(只要scrollview是滚动状态就会调用此方法) - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ //------滚动视图上面的子视图可以移动,不是子视图改变自身的frame值,而是,通过改变更改滚动视图(也就是子视图的父视图)的bounds的origin(也就是x,y)来更改子视图在父视图(滚动视图)上显示的位置 //scrollview的偏移量 CGPoint offSet = scrollView.contentOffset; NSLog(@"----%s", __func__); //得到scrollView的bounds的x点,即水平方向偏移量 NSLog(@"偏移量-----%f", offSet.x); float x = scrollView.bounds.origin.x; NSLog(@"bounds------%f", x); /*------【回顾】:bounds改变导致其子视图位置改变!!! 改变子视图位置:scrollView滚动视图通过改变自身bounds,子view左上角坐标原点发生移动*/ } //停止拖动(当手指(触摸对象)离开,正在滚动的视图减速) - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{ NSLog(@"--%s", __func__); } //视图真正静止(视图不动了) - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{ NSLog(@"%s",__func__); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end

知识点5UIScrollView和UIPageControl配合使用

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.

    // 设置背景色
    self.view.backgroundColor = [UIColor grayColor];

    // 添加UIScrollView
    self.userGuideScrollView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height)] autorelease]; // 初始化位置和大小
    self.userGuideScrollView.contentSize = CGSizeMake(self.view.frame.size.width* 11, self.view.frame.size.height); // 设置存放的内容的大小
    _userGuideScrollView.pagingEnabled = YES; // 设置scrollView按一整页滑动
    _userGuideScrollView.delegate = self; // 设置代理为当前
    _userGuideScrollView.userInteractionEnabled = YES; // 设置可以与用户交互
    _userGuideScrollView.showsHorizontalScrollIndicator = YES; // 显示滑动时候横向的滚动条
    // 添加图片到UIScrollView中
    for (int i = 1; i <= 11; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImageimageNamed:[NSString stringWithFormat:@"image%d", i]]];
        imageView.frame = CGRectMake((i - 1) * self.view.frame.size.width, 0,self.view.frame.size.width, self.view.frame.size.height);
        [_userGuideScrollView addSubview:imageView];
        [imageView release], imageView = nil;
    }
    // 添加到当前的View
    [self.view addSubview:_userGuideScrollView];


    // 初始化UIPageController
    self.scrollPageControl = [[[UIPageControl alloc] init] autorelease];
    _scrollPageControl.frame = CGRectMake(0, self.view.frame.size.height - 60,self.view.frame.size.width, 30); // 设置位置
    _scrollPageControl.numberOfPages = 11; // 设置有多少个小点点
    _scrollPageControl.currentPage = 0; // 设置当前是哪个点点
    _scrollP
首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/7/7
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS获取app图标和启动图片名字(A.. 下一篇iOS - 数组(NSArray)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目