游戏技术文章

iOS开发-UI (十)UIScrollView 和 UIPageControl使用

时间:2017-2-9 12:31:42  作者:棋牌资源网  来源:棋牌资源网  查看:8882  评论:0
内容摘要:知识点:1.UIScrollView使用2.UIPageControl使用@interface RootViewController ()=======================UIScrollView使用 ...
知识点:

1.UIScrollView使用

2.UIPageControl使用

@interface RootViewController ()<UIScrollViewDelegate>

=======================

UIScrollView使用

    1.UIScrollView创建

    2.常用属性

      1)滚动内容大小

 
@property(nonatomic) CGSize contentSize

//实例化一个滚动视图

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];

    //设置滚动区域的大小

    scrollView.contentSize = CGSizeMake(KScreenWidth * 3, KScreenHeigth *3);
 

 

      2)是否分页滚动

@property(nonatomic,getter=isPagingEnabled) BOOL pagingEnabled

scrollView.pagingEnabled = YES;

 

 

      3)设置内容位置

 
@property(nonatomic) CGPoint contentOffset

//屏幕的宽度

#define KScreenWidth [UIScreen mainScreen].bounds.size.width

//屏幕的高度

#define KScreenHeigth [UIScreen mainScreen].bounds.size.height

//设置偏移量

    //scrollView.contentOffset = CGPointMake(KScreenWidth, KScreenHeigth);

    //带动画设置偏移量

    [scrollView setContentOffset:CGPointMake(KScreenWidth, KScreenHeigth) animated:YES];

 

 

      4)显示水平滚动条

@property(nonatomic) BOOL showsHorizontalScrollIndicator

scrollView.showsHorizontalScrollIndicator= NO;

 

      5)显示垂直滚动条

@property(nonatomic) BOOL showsVerticalScrollIndicator

scrollView.showsVerticalScrollIndicator = NO;

 

      6)弹簧效果

@property(nonatomic) BOOL bounces

//关闭弹簧效果

    scrollView.bounces = NO;

 

=======================

UIScrollView的常用代理方法

1)即将开始拖拽

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView

2)即将停止拖拽

- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView 

withVelocity:(CGPoint)velocity targetContentOffset:

(inout CGPoint *)targetContentOffset

3)已经停止拖拽

scrollViewDidEndDragging:(UIScrollView *)scrollView 

willDecelerate:(BOOL)decelerate

4)即将停止减速

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView

5)已经停止减速

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

6)点击状态栏回到顶部

- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView

7)已经滑到顶部

- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView

8)放大缩小

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

9)缩放完毕

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView 

withView:(UIView *)view atScale:(CGFloat)scale

 
#pragma mark- UIScrollViewDelegate

//准备开始拖拽

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

    NSLog(@"scrollViewWillBeginDragging");

}

//准备停止拖拽

-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{

    NSLog(@"scrollViewWillEndDragging");

}

//已经停止拖拽

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

    NSLog(@"scrollViewDidEndDragging");

}

//准备开始减速

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

    NSLog(@"scrollViewWillBeginDecelerating");

}

//已经停止减速

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

    NSLog(@"偏移量为%@",NSStringFromCGPoint(scrollView.contentOffset));

    NSLog(@"scrollViewDidEndDecelerating");
}

//滚动过程中一直调用的代理方法

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

//    NSLog(@"偏移量为%@",NSStringFromCGPoint(scrollView.contentOffset));

//    NSLog(@"scrollViewDidScroll");

}

//允许点击状态栏滑动到顶部

-(BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView{

    return YES;

}

//已经滑动到顶部

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

    //NSLog(@"scrollViewDidScrollToTop");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"已经滑到最顶" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    //展示

    [alert show];
}


//设置代理

    _scrollView.delegate = self;

    //设置放大缩小的范围

    _scrollView.minimumZoomScale = 0.5;

    _scrollView.maximumZoomScale = 2;

    [self.view addSubview:_scrollView];

#pragma mark- UIScrollViewDelegate

//返回需要放大的视图

-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{

    return _imageView;
}

//放大缩小完成之后的回调方法

-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{

    //view -> 当前放大缩小的视图对象

    //scale -> 放大缩小的系数

    NSLog(@"scale = %f",scale);

    //判断

    if (scale < 1.0) {

        //缩小

        view.center = CGPointMake(scrollView.frame.size.width/2.0, scrollView.frame.size.height/2.0);

    }else{

        //放大

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

 

=======================

UIPageControl

    1.UIPageControl创建方式

    2.常用属性

   

 
  1)总页数

@property(nonatomic) NSInteger numberOfPages

//设置总页数

    _pageCtl.numberOfPages = 4;

@property(nonatomic,retain) UIColor *pageIndicatorTintColor

//设置当前页码颜色

    _pageCtl.currentPageIndicatorTintColor = [UIColor greenColor];

//其他页码颜色

    _pageCtl.pageIndicatorTintColor = [UIColor redColor];

      2)当前页数

@property(nonatomic) NSInteger currentPage

@property(nonatomic,retain) UIColor *currentPageIndicatorTintColor

 
 

 

 

    3.结合UIScrollView

      1)利用代理协议完成UIPageControl当前页的设置

 
#pragma mark- UIScrollViewDelegate

//停止减速

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

    if (scrollView.contentOffset.x == self.view.frame.size.width * 5) {

        //不能用带动画跳转

        //当移动到第六个视图的时候

        //瞬间跳转到第二个视图

        scrollView.contentOffset = CGPointMake(self.view.frame.size.width , 0);

    }else if (scrollView.contentOffset.x == 0){

        //当移动到第一个视图的时候

        //瞬间跳转到第五个视图

        scrollView.contentOffset = CGPointMake(self.view.frame.size.width * 4 , 0);
    }
    //设置页码

    _pageCtl.currentPage = scrollView.contentOffset.x/self.view.frame.size.width - 1;
}

标签:iOS开发-UI(十)UIScrollView和UIPageControl使用 

欢迎加入VIP,【VIP售价:只要288元永久VIP会员】畅享商业棋牌游戏程序下载,点击开通!

下载说明


☉本站所有源码和资源均由站长亲自测试-绝对保证都可以架设,运营!
☉如源码和资源有损坏或所有链接均不能下载,请告知管理员,

☉本站软件和源码大部分为站长独资,资源购买和收集,放心下载!

☉唯一站长QQ:1004003180  [人格担保-本站注重诚信!]

☉购买建议E-mail:1004003180@qq.com   源码收购 E-mail:1004003180@qq.com    

☉本站文件解压密码  【文章内都自带解压密码,每个密码不同!】


本站提供的所有源码,均来源站长提供,仅学习交流 浙ICP备09009969号

由此产生不良后果和法律责任与本站无关,如果侵犯了您的版权,请来信告知 1004003180@qq.com 将及时更正和删除! 

Copyright © 2008-2021 棋牌资源网,你身边的棋牌资源下载站    All Rights Reserved