zoukankan      html  css  js  c++  java
  • UIScrollView和UIPageControl

    UIScrollView和UIPageControl 一般配合使用

    //创建一个滑动/滚动的视图,大小和当前视图大小一样(可以自定义大小)
        UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:self.view.bounds];
        //设置显示内容区域的大小,宽度是当前视图的6倍(可以自定义大小),
        scrollView.contentSize=CGSizeMake(self.view.frame.size.width*6, self.view.frame.size.height);
        //设置视图左上角距离坐标原点的偏移量,
        scrollView.contentOffset=CGPointMake(10, 10);
        //是否整屏翻动 大于1/2就翻动,否则不反动
        scrollView.pagingEnabled=YES;
        //设置边界是否回弹
        scrollView.bounces=NO;
        //设置是否能够滚动
        scrollView.scrollEnabled=YES;
        //设置缩小的最小比例,本例设置成0.8
        scrollView.minimumZoomScale=0.8;
        //设置放大的最大比例,本例最大设置成2.0
        scrollView.maximumZoomScale=2.0;

    //设置代理
        scrollView.delegate=self;
        scrollView.tag=1001;

    //UIScrollView 的代理delegate,指定缩放的视图是谁
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
        UIImageView *imageView=(UIImageView *)[scrollView viewWithTag:1001];
        return imageView;
    }

    - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
        NSLog(@"动画");
    }

    //开始减速时触发
    - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
        NSLog(@"开始减速");
    }

    //结束减速时触发
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        NSLog(@"结束减速");
    }

    //将要被拖拽时触发
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        NSLog(@"将要被拖拽");
    }
    //将要结束拖拽时触发
    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0){
        NSLog(@"将要结束拖拽");
    }
    //已经结束拖拽时触发
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
        NSLog(@"已经结束拖拽");
    }

    //scrollView正在滚动的时候会触发该方法
    //- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //    NSLog(@"正在滚动");
    //}

    //结束缩放, 实现缩放完成之后的协议方法
    -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
        view.center=self.view.center;
        
    }

    //创建一个页面管理器

    UIPageControl *pageControl=[[UIPageControl alloc] initWithFrame:CGRectMake(60, 600, 200, 50)];
        //pageControl.backgroundColor=[UIColor grayColor];
        //设置页面个数
        pageControl.numberOfPages=6;
        //设置当前页的位置
        pageControl.currentPage=1;
        //设置当前页 指示器的颜色,设置选中的圆点的颜色
        pageControl.currentPageIndicatorTintColor=[UIColor blueColor];
        //设置未选中圆点的颜色
        pageControl.pageIndicatorTintColor=[UIColor redColor];
        
        
        //继承control可以调用他的add添加方法
        [pageControl addTarget:self action:@selector(changeValue:) forControlEvents:UIControlEventValueChanged];

    //通过pageControl里面的页面控制scrollview中的内容显示

    //在pagecrotoll中添加方法 pageControl是创建的对象,

    [pageControl addTarget:self action:@selector(changePageNum:) forControlEvents:UIControlEventValueChanged];

    //方法的实现 sceollView是 滚动视图的对象

    -(void)changePageNum:(UIPageControl *)page{
        scrollView.contentOffset=CGPointMake(pageControl.currentPage*(self.view.frame.size.width), 0);
    }
    //通过scrollView控制pageControl的当前currentpage

    //添加代理

    scrollView.delegate=self;

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollViews{
        int num=(int)(scrollViews.contentOffset.x/self.view.frame.size.width);
        pageControl.currentPage=num;
    }

  • 相关阅读:
    angular手势事件之on-Hold
    angular 控制器的使用两种模式
    关于IONIC 报错 XX is not a function
    ionic 中$ionicView.beforeEnter 事件的一个bug
    开发一个IONIC应用的首要操作(宏观)
    在线常用库 + API手册
    关于日历实现代码里lunarInfo(农历)数组
    YSlow
    GET and POST
    Yahoo34条军规——雅虎WEB前端网站优化
  • 原文地址:https://www.cnblogs.com/shao621/p/4581834.html
Copyright © 2011-2022 走看看