设置屏幕效果

import UIKitclass ViewController: UIViewController {    //获取屏幕的宽  let kScreenWidth=UIScreen.main.bounds.size.width    //获取屏幕的高    let kScreeHeight=UIScreen.main.bounds.size.height    override func viewDidLoad() {        super.viewDidLoad()        //UIScrollView:滚动视图,是所有滚动视图的基类,只要一个视图能够滚动,要么是UIScrollView,要是UIScrollView的子类,。UIScrollView有俩个重要字类:UITableView,UICollectionView        //什么时候需要滚动:当我们内容区域。大于可现区域的时候,为了看到更多内容,才需要滚动去查看。        //创建UIScrollView        let scrollView=UIScrollView(frame: CGRect(x: 20, y: 20, width: kScreenWidth-40, height: kScreeHeight-40))        scrollView.backgroundColor=#colorLiteral(red: 1, green: 0.9047565644, blue: 0.9592488978, alpha: 1)        //设置scrollView内容区域大小        scrollView.contentSize=CGSize(width: kScreenWidth*3, height: kScreeHeight*2)              //设置scrollView 的偏移量        //scrollView.contentOffset=CGPoint(x: kScreenWidth, y: 0)        //设置滚动条的样式        scrollView.indicatorStyle = .white        //设置是否显示滚动条        //垂直滚动条        scrollView.showsVerticalScrollIndicator=false        scrollView.showsHorizontalScrollIndicator=false        //方向锁,滚动时候只能朝一个方向滚动        scrollView.isDirectionalLockEnabled=true        //设置是否有弹簧xiaoguo        //scrollView.bounces=false        //设置水平方向有弹簧效果        scrollView.alwaysBounceHorizontal=true        //设置垂直方向有弹簧效果        scrollView.alwaysBounceVertical=true        //设置是否支持整页滚动        scrollView.isPagingEnabled=true        //设置scrollView是否支持滚动        scrollView.isScrollEnabled=true        scrollView.scrollsToTop=true        //代理属性        //设置是否支持回到顶部        scrollView.delegate=self        //设置最小缩放比例        scrollView.minimumZoomScale=1.0        //设置最大缩放比例        scrollView.maximumZoomScale=3      self.view.addSubview(scrollView)                                let imageView=UIImageView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 2*kScreeHeight))        imageView.image=#imageLiteral(resourceName: "image.jpg")        imageView.tag=200        scrollView.addSubview(imageView)                                    }}//在延展中管理UIScrollViewDelegate的协议方法extension ViewController:UIScrollViewDelegate{  //1  当ScrollView滚动的时候这个方法会持续触发    func scrollViewDidScroll(_ scrollView: UIScrollView) {// any offset changes        print("滚动着,滚动着")        print(scrollView.contentOffset)    }    //2缩放过程中持续触发    func scrollViewDidZoom(_ scrollView: UIScrollView) {// any zoom scale changes  print("缩放着,缩放着")        print(scrollView.zoomScale)        // called on start of dragging (may require some time and or distance to move)    }    //3开始拖拽时候触发    func scrollViewWillBeginDragging(_ scrollView: UIScrollView){    print("开始拖拽了")    // called on finger up if the user dragged. velocity is in points/millisecond. targetContentOffset may be changed to adjust where the scroll view comes to rest    }    //4将要结束拖拽的时候触发    func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer){

print("将要结束")

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards

}

//5已经结束拖拽时候触发

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool){

print("结束拖拽")

}

//6将要开始减速的时候触发

func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {

print("将要开始减速")

// called on finger up as we are moving

}

//7减速完成,速度为零,这个方法很重要,往往就是在这个方法获取偏量

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {// called when scroll view grinds to a halt

print("减速完成呢")

}

//8给scrollView设置一个结束动画的时候触发,不制定动画就不会触发

func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) {// called when setContentOffset/scrollRectVisible:animated: finishes. not called if not animating

}

//9返回scrollView缩放视图

func viewForZooming(in scrollView: UIScrollView) -> UIView? {// return a view that will be scaled. if delegate returns nil, nothing happens

return scrollView.viewWithTag(200)

}

//10将要开始缩放的时候触发

func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?){ // called before the scroll view begins zooming its content

}

//11结束缩放的时候触发

func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {// scale between minimum and maximum. called after any 'bounce' animations

}

//12设置点击状态栏是否能回到顶部

func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {// return a yes if you want to scroll to the top. if not defined, assumes YES

return true

}

//13scrollView回到顶部触发的方法

func scrollViewDidScrollToTop(_ scrollView: UIScrollView){

print("scrllView已经回到顶部")

}

}

import UIKit

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

self.window=UIWindow(frame: UIScreen.main.bounds)

self.window?.backgroundColor=#colorLiteral(red: 1, green: 0.3980397582, blue: 0.7863847613, alpha: 1)

//设为主屏幕,以及使其可见

self.window?.makeKeyAndVisible()

self.window?.rootViewController=ViewController()

return true

}

func applicationWillResignActive(_ application: UIApplication) {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

func applicationDidEnterBackground(_ application: UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(_ application: UIApplication) {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(_ application: UIApplication) {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(_ application: UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,843评论 6 502
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,538评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,187评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,264评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,289评论 6 390
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,231评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,116评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,945评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,367评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,581评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,754评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,458评论 5 344
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,068评论 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,692评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,842评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,797评论 2 369
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,654评论 2 354

推荐阅读更多精彩内容