标签:
创建scrollview
scrollView = UIScrollView() scrollView.delegate = self scrollView.frame = self.view.bounds let imageView = UIImageView(image: UIImage(named: "0")) scrollView.contentSize = imageView.bounds.size scrollView.addSubview(imageView) self.view.addSubview(scrollView)
设置属性
scrollView.minimumZoomScale = 0.5//最小比例 scrollView.maximumZoomScale = 2//最大比例 scrollView.scrollsToTop = true//点击状态栏回到顶端(默认是YES) scrollView.alwaysBounceHorizontal = true//水平方向拖到末尾是否反弹 scrollView.alwaysBounceVertical = true//垂直方向反弹 scrollView.bounces = true//超出边界有反弹 scrollView.scrollEnabled = false//是否允许滚动
UIScrollViewDelegate 先遵守协议 UIScrollViewDelegate
滚动过程中一直执行该方法
func scrollViewDidScroll(scrollView: UIScrollView) { print("x:\(scrollView.contentOffset.x) y:\(scrollView.contentOffset.y)") }
拖拽完成后执行
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) { print(scrollView.contentOffset) }
手势放大缩小
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? { for subView : AnyObject in scrollView.subviews{ if subView.isKindOfClass(UIImageView){ return subView as? UIView } } return nil }
标签:
原文地址:http://www.cnblogs.com/spaceID/p/4977449.html