import UIKit

class ViewController: UIViewController ,UIScrollViewDelegate{

override func viewDidLoad() {

super.viewDidLoad()

let scrollView = UIScrollView.init()

scrollView.frame = self.view.bounds

let imageView = UIImageView.init(image: UIImage.init(named: "1"))

scrollView.contentSize = imageView.bounds.size

scrollView.addSubview(imageView)

self.view.addSubview(scrollView)

// 手势缩放大小

// 要实现放大缩小功能, 需要指定 UIScrollView 的允许缩放的最大和最小比例 (默认都是 1.0)

// 同时 delegate 属性指定一个委托类, 委托类要继承 UIScrollViewDelegate 协议, 并实现 viewForZooming 方法

scrollView.minimumZoomScale = 0.1 //最小比例

scrollView.maximumZoomScale = 3 //最大比例

scrollView.delegate = self

}

func viewForZooming(in scrollView: UIScrollView) -> UIView? {

for subview : AnyObject in scrollView.subviews {

if subview.isKind(of: UIImageView.classForCoder()) {

return subview as? UIView

}

}

return nil

}

//视图滚动中一直触发

func scrollViewDidScroll(_ scrollView: UIScrollView) {

print("x:\(scrollView.contentOffset.x) y:\(scrollView.contentOffset.y)")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

swift 实践- 14 -- UIScrollView的更多相关文章

  1. swift 实践- 08 -- UISegmentedControl

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  2. swift 学习- 14 -- 继承

    // 一个类可以继承另一个 类的方法, 属性和其他特征, 当一个类继承其他类时, 继承类叫子类, 被继承类叫父类 或 (超类), 在 Swift 中, 继承是区分 [类] 和其他类型的 一个基本特征 ...

  3. es6+最佳入门实践(14)

    14.模版字符串 模版字符串(template string)是增强版的字符串,定义一个模版字符串需要用到反引号 let s = `这是一个模版字符串` console.log(s) 14.1.模版字 ...

  4. Swift 实践之UIWebView

    1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createEle ...

  5. ASP.NET-FineUI开发实践-14

    以前写过一个表格自动补全,改下,就出现了部分级联修改.测试版本4.1.1 共享下JS,ext-part2.js       后台再来个得到数据的方法就可以了.   1.方法还是删除+插入,主要在  i ...

  6. swift 实践- 13 -- UIStepper

    import UIKit class ViewController: UIViewController { var stepper: UIStepper! var label: UILabel! ov ...

  7. swift 实践- 12 -- UIPickerView

    import UIKit class ViewController: UIViewController , UIPickerViewDelegate,UIPickerViewDataSource{ v ...

  8. swift 实践- 11 -- UISlider

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  9. swift 实践- 10 -- UIProgressView

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

随机推荐

  1. linux关闭防火墙及开放端口

    1) 重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 2) 即时生效,重启后失效 开启: service iptables sta ...

  2. MySQL api

    今天看去年年中写的代码,留意到一个关键时刻能提高效率的api:on duplicate key update: 语法: INSERT INTO INSERT INTO g_iot_user_build ...

  3. 利用PHP连接数据库——实现用户数据的增删改查的整体操作实例

    main页面(主页面) <table width="100%" border="1" cellpadding="0" cellspac ...

  4. 1.3 第一个python程序

    使用Pycharm编写第一个python程序 1.打开 Pycharm,选择 Create New Project,创建一个新项目 2.选择Pure Python表示创建一个纯Python程序项目,  ...

  5. cpp for each

    第一种 自动推导类型i从arr的地址0 之后地址向下循环向I赋值 for(auto i:arr){ }//arr内的值不会变 第二种  自动推导类型i从arr的地址0 之后地址向下循环向I赋地址 fo ...

  6. CentOS7.2通过Yum安装MySQL5.7

    1 下载源 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2安装源 yum localinstall ...

  7. 通过Cookie统计上次网页访问时间

    servlet类: import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date; import ...

  8. 「LibreOJ Round #6」花火

    转化思维的好题! 链接:here 大致题意: 有$ n$个数字,你每次可以交换相邻两个,还有一次交换任意两个元素的机会,求最少的交换次数使得这些数字升序排序(原数列两两不同) $ solotion:$ ...

  9. ionic 照相机 Camera

    1.官网: https://ionicframework.com/docs/native/camera/#DestinationType 2.引入插件 $ ionic cordova plugin a ...

  10. django 学习手册 - ORM 报错集(随时更新)

    报错问题: 问题一:(1050代码) django.db.utils.InternalError: (1050, "Table 'app01_group' already exists&qu ...