• 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
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    暑假集训Day14 I (莫队)
    暑假集训Day14 G (gcd 数学)
    暑假集训Day13 H (进制转换 数学)
    暑假集训Day13 C (二分+贪心)
    暑假集训Day13 I (区间DP)
    暑假集训Day12 H (数论 STL)
    Java8中list转map方法总结
    Typora ---一款简洁的Markdown编辑器
    java8 map flatmap
    Elasticsearch基本查询总结
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193208.html
Copyright © 2020-2023  润新知