UIScrollView

建立scrollviewhtml

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)

設置屬性spa

scrollView.minimumZoomScale = 0.5//最小比例
scrollView.maximumZoomScale = 2//最大比例
scrollView.scrollsToTop = true//點擊狀態欄回到頂端(默認是YES)
scrollView.alwaysBounceHorizontal = true//水平方向拖到末尾是否反彈
scrollView.alwaysBounceVertical = true//垂直方向反彈
scrollView.bounces = true//超出邊界有反彈
scrollView.scrollEnabled = false//是否容許滾動

UIScrollViewDelegate 先遵照協議 UIScrollViewDelegatehtm

滾動過程當中一直執行該方法blog

func scrollViewDidScroll(scrollView: UIScrollView) {
    print("x:\(scrollView.contentOffset.x)  y:\(scrollView.contentOffset.y)")
}

拖拽完成後執行get

func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    print(scrollView.contentOffset)
}

手勢放大縮小it

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 class

相關文章
相關標籤/搜索