// Created by dongqiangfei on 16/3/17.
// Copyright © 2016年 dongqiangfei. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UIScrollViewDelegate{
var ExampleScorllView : UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
MakeScrollView()
// Do any additional setup after loading the view, typically from a nib.
}
private func MakeScrollView() {
self.ExampleScorllView = UIScrollView.init()
self.ExampleScorllView.frame = CGRectMake(0, 64, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height - 64)
self.ExampleScorllView.backgroundColor = UIColor.orangeColor()
self.view .addSubview(self.ExampleScorllView)
//设置缩放最大最小倍数
self.ExampleScorllView.minimumZoomScale = 0.3
self.ExampleScorllView.maximumZoomScale = 3
self.ExampleScorllView.delegate = self
self.ExampleScorllView.contentSize = CGSizeMake(UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height*3)
//设置滑动条的样式
self.ExampleScorllView.indicatorStyle = UIScrollViewIndicatorStyle.White
//取消滑动条
self.ExampleScorllView.showsHorizontalScrollIndicator = true//水平
self.ExampleScorllView.showsVerticalScrollIndicator = true//竖直
//设置反弹效果
self.ExampleScorllView.bounces = false
//设置默认偏移量
self.ExampleScorllView.contentOffset = CGPointMake(0, 300)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
print("X:\(scrollView.contentOffset.x) Y:\(scrollView.contentOffset.y)")
print("滑动中")
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
print("停止拖拽")
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("停止滑动")
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return scrollView.subviews[0] as? UIView
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}