zoukankan      html  css  js  c++  java
  • 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
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    SQLMAP注入教程-11种常见SQLMAP使用方法详解
    VS2012/2013/2015/Visual Studio 2017 关闭单击文件进行预览的功能
    解决 IIS 反向代理ARR URLREWRITE 设置后,不能跨域跳转 return Redirect 问题
    Spring Data JPA one to one 共享主键关联
    JHipster 问题集中
    Spring Data JPA 定义超类
    Spring Data JPA查询关联数据
    maven命名
    maven仓库
    Jackson读取列表
  • 原文地址:https://www.cnblogs.com/iQingYang/p/5193208.html
Copyright © 2011-2022 走看看