Swift_ScrollView _ API详解


GitHub

class ViewController: UIViewController,UIScrollViewDelegate {

    var scrollView = UIScrollView()
var imageView = UIImageView()
var image = UIImage() override func viewDidLoad() {
super.viewDidLoad() self.image = UIImage.init(named: "test")!
self.imageView.image = self.image self.view.backgroundColor = UIColor.green
self.view.addSubview(self.scrollView)// 将ScrollView添加到视图上 let width = self.view.bounds.size.width * 2
let height = self.view.bounds.size.height * 2 self.scrollView.frame = self.view.bounds // 设置scrollView的 frame
self.scrollView.contentSize = CGSize(width:width, height:height) //设置scrollView的 contentSize
self.scrollView.delegate = self // 设置scrollView的 代理 print(self.scrollView.contentOffset) // scrollView左顶点的位置 可设置
print(self.scrollView.contentInset) // scrollView 添加额外的滚动附近区域的内容 可设置
self.scrollView.isDirectionalLockEnabled = true
print(self.scrollView.isDirectionalLockEnabled) // 锁定垂直或水平滚动 可设置
print(self.scrollView.bounces) // scrollView 回弹效果 可设置
print(self.scrollView.alwaysBounceVertical) // 垂直回弹 可设置
print(self.scrollView.alwaysBounceHorizontal) // 水平回弹 可设置
print(self.scrollView.isPagingEnabled) // 分页 可设置
print(self.scrollView.isScrollEnabled) // 滚动 可设置
print(self.scrollView.showsHorizontalScrollIndicator) // 显示水平滚动条
print(self.scrollView.showsVerticalScrollIndicator) // 显示垂直滚动条
print(self.scrollView.scrollIndicatorInsets) // 调整指标insets的内部
print(self.scrollView.indicatorStyle) // black with white border. good against any background
print(self.scrollView.decelerationRate) // 减速速度 //open func setContentOffset(_ contentOffset: CGPoint, animated: Bool) 设置 contentOffset
//open func scrollRectToVisible(_ rect: CGRect, animated: Bool) 这个方法需要传入一个Rect 这个rect可以理解成在scrollview.contentView中frame 调用这个方法就会滚到rect所在的那个区域去
//open func flashScrollIndicators() 短暂地显示滚动指示器 你应该在把滚动视图放在最前端时调用此方法。 /* open var isTracking: Bool { get } // returns YES if user has touched. may not yet have started dragging open var isDragging: Bool { get } // returns YES if user has started scrolling. this may require some time and or distance to move to initiate dragging open var isDecelerating: Bool { get } // returns YES if user isn't dragging (touch up) but scroll view is still moving open var delaysContentTouches: Bool // default is YES. if NO, we immediately call -touchesShouldBegin:withEvent:inContentView:. this has no effect on presses open var canCancelContentTouches: Bool // default is YES. if NO, then once we start tracking, we don't try to drag if the touch moves. this has no effect on presses
*/ //父视图是否可以将消息传递给子视图 yes是将事件传递给子视图 则不滚动 no是不传递则继续滚动
//open func touchesShouldBegin(_ touches: Set<UITouch>, with event: UIEvent?, in view: UIView) -> Bool //父视图是否可以将消息传递给子视图 yes是将事件传递给子视图 则不滚动 no是不传递则继续滚动
//open func touchesShouldCancel(in view: UIView) -> Bool print(self.scrollView.minimumZoomScale) // 最小的变焦比例 可设置
print(self.scrollView.maximumZoomScale) // 最大的变焦比例 可设置
print(self.scrollView.zoomScale) // 当前的变焦比例 //open func setZoomScale(_ scale: CGFloat, animated: Bool) 设置变焦比例
//open func zoom(to rect: CGRect, animated: Bool) print(self.scrollView.bouncesZoom)
print(self.scrollView.isZooming)
print(self.scrollView.isZoomBouncing)
print(self.scrollView.scrollsToTop) //当用户点击状态栏时 是否滚动到顶部 //panGestureRecognizer 拖动手势
//pinchGestureRecognizer 变焦手势 //keyboardDismissMode 键盘消失形式
//refreshControl self.imageView.frame = CGRect(origin:CGPoint(x:0, y:0),size:CGSize(width:width, height:height))
self.scrollView.addSubview(self.imageView) } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
} /// MARK: UIScrollViewDelegate 代理
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrollViewDidScroll:scrollView 在滚动")
}
func scrollViewDidZoom(_ scrollView: UIScrollView) {
print("scrollViewDidZoom:scrollView 在改变变焦比例")
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
print("scrollViewWillBeginDragging:scrollView 即将被拖拽")
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
print("scrollViewWillEndDragging:scrollView 即将结束拖拽")
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
print("scrollViewDidEndDragging:scrollView 已经结束拖拽")
}
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
print("scrollViewWillBeginDecelerating:scrollView 即将开始减速")
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
print("scrollViewDidEndDecelerating:scrollView 已经开始减速")
}
func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {
print("scrollViewDidEndScrollingAnimation:scrollView 已经结束动画")
}
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
print("viewForZooming:scrollView 返回视图(viewForZooming)")
return nil
}
func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
print("scrollViewWillBeginZooming:scrollView 即将开始变焦")
}
func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
print("scrollViewDidEndZooming:scrollView 已经结束变焦")
}
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
print("scrollViewShouldScrollToTop:scrollView 即将回滚到顶部")
return true
}
func scrollViewDidScrollToTop(_ scrollView: UIScrollView) {
print("scrollViewShouldScrollToTop:scrollView 已经回滚到顶部")
}
}

Swift_ScrollView _ API详解的更多相关文章

  1. 大数据学习笔记——Spark工作机制以及API详解

    Spark工作机制以及API详解 本篇文章将会承接上篇关于如何部署Spark分布式集群的博客,会先对RDD编程中常见的API进行一个整理,接着再结合源代码以及注释详细地解读spark的作业提交流程,调 ...

  2. Java 8 Stream API详解--转

    原文地址:http://blog.csdn.net/chszs/article/details/47038607 Java 8 Stream API详解 一.Stream API介绍 Java8引入了 ...

  3. jqGrid APi 详解

    jqGrid APi 详解 jqGrid皮肤 从3.5版本开始,jqGrid完全支持jquery UI的theme.我们可以从http://jqueryui.com/themeroller/下载我们所 ...

  4. hibernate学习(2)——api详解对象

    1   Configuration 配置对象 /详解Configuration对象 public class Configuration_test { @Test //Configuration 用户 ...

  5. 网络编程socket基本API详解(转)

    网络编程socket基本API详解   socket socket是在应用层和传输层之间的一个抽象层,它把TCP/IP层复杂的操作抽象为几个简单的接口供应用层调用已实现进程在网络中通信. socket ...

  6. 转】Mahout推荐算法API详解

    原博文出自于: http://blog.fens.me/mahout-recommendation-api/ 感谢! Posted: Oct 21, 2013 Tags: itemCFknnMahou ...

  7. dom4j api 详解--XPath 节点详解

    dom4j api 详解 http://871421448.iteye.com/blog/1546955 XPath 节点 http://www.w3school.com.cn/xpath/xpath ...

  8. 百度地图API详解之事件机制,function“闭包”解决for循环和监听器冲突的问题:

    原文:百度地图API详解之事件机制,function"闭包"解决for循环和监听器冲突的问题: 百度地图API详解之事件机制 2011年07月26日 星期二 下午 04:06 和D ...

  9. 【Unity编程】Unity中关于四元数的API详解

    本文为博主原创文章,欢迎转载,请保留出处:http://blog.csdn.net/andrewfan Unity中关于四元数的API详解 Quaternion类 Quaternion(四元数)用于计 ...

随机推荐

  1. 软件项目技术点(1)——d3.interpolateZoom-在两个点之间平滑地缩放平移

    AxeSlide软件项目梳理   canvas绘图系列知识点整理 软件参考d3的知识点 我们在软件中主要用到d3.js的核心函数d3.interpolateZoom - 在两个点之间平滑地缩放平移.请 ...

  2. 一周一个小demo — vue.js实现备忘录功能

    这个vue实现备忘录的功能demo是K在github上找到的,K觉得这是一个用来对vue.js入门的一个非常简单的demo,所以拿在这里共享一下. (尊重他人劳动成果,从小事做起~  demo原git ...

  3. html+css中常见的浏览器兼容性处理

    1.居中问题 div里的内容,IE默认为居中,而FF默认为左对齐,可以尝试增加代码margin: 0 auto; 2.高度问题 两上下排列或嵌套的div,上面的div设置高度(height),如果di ...

  4. CentOS 7运维管理笔记(7)----Apache 基于端口的虚拟主机配置

    如果一台服务器只有一个IP或需要通过不同的端口访问不同的虚拟主机,可以使用基于端口的虚拟主机配置. (1) 在虚拟机的CentOS7服务器上配置 eth0:4 为192.168.1.214: (2) ...

  5. linux多线程编程——读者优先、写者优先问题

    读者优先描述 如果读者来: 1) 无读者.写着,新读者可以读: 2) 无写者等待,但有其他读者正在读,新读者可以读: 3) 有写者等待,但有其他读者正在读,新读者可以读: 4) 有写者写,新读者等 如 ...

  6. hdu 1102 Constructing Roads (Prim算法)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Constructing Roads Time Limit: 2000/1000 MS (Jav ...

  7. Math类中常用方法

    public static int abs(int a) , public static long abs(long a), public static float abs(float a),  pu ...

  8. phantomjs rendering

    http://wwwy3y3.ghost.io/pageres-phantomjs-capture-sreenshot-chinese-fonts-not-render-correctly/ 在使用中 ...

  9. MySQL案例之Timestamp和Datetime

    mysql数据库常用的时间类型有timestamp和datetime,两者主要区别是占用存储空间长度不一致.可存储的时间也有限制,但针对不同版本下,timestamp字段类型的设置需要慎重,因为不注意 ...

  10. Python学习---Python下[元组]的学习

    元组是不可变的, 用小括号()定义,而且一旦定义 ,不可变[类型是tuple] [元组看做一个整体,不可拆分,不可赋值,但可以全部重新赋值] 通过圆括号,用逗号分隔,常用在使语句或用户定义的函数能够安 ...