您的位置:首页 > 移动开发 > Swift

ios开发系列之Swift_UI_ScrollVIew

2016-03-17 10:04 363 查看
原文链接:https://www.geek-share.com/detail/2669180240.html

//  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.

    }

    

}

 

转载于:https://www.cnblogs.com/godlovexq/p/5286233.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: