• UIScrollView


     
    //
    //  ViewController.m
    //  UIScrollView01
    //
    //  Created by cqy on 16/2/15.
    //  Copyright © 2016年 程清杨. All rights reserved.
    //

    #import "ViewController.h"
    #define WIDTH   [[UIScreen mainScreen] bounds].size.width
    #define HEIGHT  [[UIScreen mainScreen]bounds].size.height
    @interface ViewController ()<UIScrollViewDelegate>{
        UIScrollView *scroll;
    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {
        [super viewDidLoad];
      
        UIImageView *img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"a"]];
        img.frame = CGRectMake(100, 0, 150, 150);
        //设置tag值,为了后⾯缩放的delegate(在controller⾥)取到img
        img.tag = 100;
       
        scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 130, WIDTH, 150)];
        scroll.backgroundColor = [UIColor greenColor];
        //属性
        //contentsize,能够滑动的决定性因素(能够决定滚动的范围)
        scroll.contentSize = CGSizeMake(2*WIDTH, 600);
        //contentOffset 偏移
       // scroll.contentOffset = CGPointMake(-50, -50);
        //返回顶部
        scroll.scrollsToTop = YES;
        //整页滑动
        scroll.pagingEnabled = YES;
        //边界反弹
        scroll.bounces = YES;
        //能否滚动
        scroll.scrollEnabled = YES;
        //水平滚动条
        scroll.showsHorizontalScrollIndicator = YES;
        //垂直滚动条
        scroll.showsVerticalScrollIndicator = YES;
        scroll.delegate = self;
        [self.view addSubview:scroll];
       
        [scroll addSubview:img];

        // Do any additional setup after loading the view, typically from a nib.
    }
    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
          NSLog(@"已经滚动...");
    }
    -(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
        NSLog(@"将要开始拖拽..");
    }
    -(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
         NSLog(@"已经结束拖拽..");
    }
    -(void)scrollViewWillBeginDecelerating:(UIScrollView
                                           *)scrollView{
        NSLog(@"将要开始减速..");
    }
    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        NSLog(@"结束减速..");
    }
    // 缩放有关
    // 缩放开始
    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
       
        return [scrollView viewWithTag:100];
    }
    // 缩放结束
    -(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale{
        NSLog(@"结束....");
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    @end
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    pytest中参数化 @pytest.mark.parametrize()
    sublime text3 更换主题
    pytest中的assert断言
    python下文件的删除以及文件目录的清空
    python 在虚拟环境中安装项目依赖requirements.txt
    pycharm中配置默认的作者信息模板
    公司八点准点播放的歌曲《共和国之恋》
    应用程序pycharm 无法打开 【jetbrains家族软件打开报错】
    macbook 安装homebrew失败
    中文分词概述及结巴分词原理
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193208.html
Copyright © 2020-2023  润新知