zoukankan      html  css  js  c++  java
  • UI学习笔记---第七天

    UIScrollView   滚动视图

    UIScrollView的常用属性

    iPone屏幕大小限制了内容的显示,UIScrollView 类提供了屏幕滚动功能

    UIScrollView是所有滑动视图的基类,UItableView   ,  UITextView等视图都是继承于此类

    使用场景:显示不下(单张大图),内容太多(图文混排),需要滚动,滚动头条(图片),相册等

    UIScrollView的常用常用属性

    contentSize //定义内容区域⼤小,决定是否能够滑动

    contentOffset //屏幕左上⾓距离坐标原点的偏移量 

    scrollsToTop //滑动到顶部(点状态条的时候) 

    pagingEnabled //是否整屏翻动

    bounces //边界是否回弹

    scrollEnabled //判断控件是否能够滚动

    showsHorizontalScrollIndicator //控制是否显⽰示⽔水平⽅方向的滚动条

    showVerticalScrollIndicator  //控制是否显⽰示垂直⽅方向的滚动条

    alwaysBounceVertical    //控制垂直⽅方向遇到边框是否反弹

    alwaysBounceHorizontal  //控制⽔水平⽅方向遇到边框是否反弹

    UIScrollView还支持处理缩放的动作,比如图片的缩小或者地图

    UIScrollView的缩放常用属性

    minimumZoomScale // 缩小的最⼩⽐例

    maximumZoomScale //放大的最⼤比例

    zoomScale   //设置变化比例

    zooming    //判断是否正在进⾏缩放反弹

    bouncesZoom //控制缩放的时候是否会反弹

    UIScrollView代理方法

    UIPageControl

    用于指示当前第几页(代码)  通常与UIScrollView 配合使用

    currentPage  //当前页      numberOfPages   //指定页面的个数

    UIPageControl父类是UIControl可以和button一样添加事件,只不过事件触发使用的不是UIControlEventsTouchUpInside而是 UIControlEventsValueChanged

    通常情况下UIPageControl与UIScrollView配合使用

    //根视图控制器中代码,[UIColor randomColor]为扩展UIColor的分类
    #import "RootViewController.h"
    #import "UIColor+NewColor.h"
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    - (void)exchange:(UIPageControl *)page
    {
    //[self]
        NSLog(@"%d",page.currentPage);//当前第几页,从0开始
        //原点变化,scroll中得label也跟着切换
        [_scroll setContentOffset:CGPointMake(100*page.currentPage, 0) animated:YES];
    //    _scroll.contentOffset = CGPointMake(100*page.currentPage, 0);
    }
    //给定某个视图进行缩放
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
    {
        return [scrollView.subviews objectAtIndex:1];
    
    }
    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
    
    {
        _page.currentPage = scrollView.contentOffset.x/100;
    }
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
            // Custom initialization
        }
        return self;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        //创建scrollview视图
        _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 40, 100, 100)];
        //设置背景颜色
        _scroll.backgroundColor = [UIColor redColor];
        _scroll.contentSize = CGSizeMake(500, 100);
        _scroll.pagingEnabled = YES;//一次划一屏
    //    scroll.scrollsToTop = YES;//点击状态栏,跳转到scrollview的最上面
    //    scroll.bounces = YES;//设置到边界的时候是否回弹
    //    scroll.scrollEnabled = NO;  //判断控件是否能够滚动
    //    scroll.showsHorizontalScrollIndicator = YES;//控制是否显示水平方向的滚动条
    //    scroll.contentOffset = CGPointMake(100, 200);//初始状态,显示哪一个label
        //缩放中影响contentsize大小,缩放后不能移动
        //最小缩放比例
    //    scroll.minimumZoomScale = 0.2;//缩小02.倍
        //最大缩放比例
    //    scroll.maximumZoomScale = 5;//扩大5倍
        _scroll.delegate = self;//让控制器成为delegate处理一些事务
        [self.view addSubview:_scroll];
        
    
        
        for (int i = 0; i<5; i++) {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100*i, 0, 100, 100)];
                label.backgroundColor = [UIColor randomColor];
                label.text = [NSString stringWithFormat:@"第%d行",i+1];
                label.textAlignment = NSTextAlignmentCenter;
                [_scroll addSubview:label];
                [label release];
    
        }
        
       
        [_scroll release];
        
        
        
        _page = [[UIPageControl alloc] initWithFrame:CGRectMake(10, 250, 300, 20)];
        _page.backgroundColor = [UIColor orangeColor];
        _page.numberOfPages = 6;
    //    page.currentPage = 3;
        [_page addTarget:self action:@selector(exchange:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:_page];
        [_page release];
        // Do any additional setup after loading the view.
    }
  • 相关阅读:
    C++ 如何判断所调用的重载函数
    C++ 入门5 类和动态内存分配(一)
    c#动态创建ODBC数据源
    设为首页,加入收藏,联系我们
    ASP.NET 2.0中CSS失效
    typedef的四个用途和两个陷阱(转)
    VC++实现应用程序对插件的支持(转)
    DOM无关事件
    How to Migrate from WCF Web API to ASP.NET Web API
    Using ASP.NET Web API with ASP.NET Web Forms
  • 原文地址:https://www.cnblogs.com/limicheng/p/3850234.html
Copyright © 2011-2022 走看看