1、安裝Python2.7
之所以是2.7而不是3.x,因為大多數庫只支持2.x,裝3.x簡直就是作死。Windows安裝包最后有個選項問你是否設置運行環境,勾上,省略修改Path這一步。
2、安裝easy_install
在這里找到ez_setup.py腳本,下載到本地,雙擊運行,一個DOS窗口閃了一下就裝好了。
3、安裝pip
開個DOS
easy_install pip
4、安裝virtualenv
pip install virtualenv
5、新建一個目錄,并在里邊創建virtualenv環境,在DOS下
$ mkdir myproject
$ cd myproject
$ virtualenv venv
這時你創建的myproject文件夾里面就多了一個venv文件夾
6、激活虛擬環境
$ venv\scripts\activate
現在命令行前面多了個(venv)表示你在venv環境內
7、在virtualenv里安裝Flask
pip install Flask
收工
另:據說安裝virtualenv會自動安裝pip,所以第3、4步可以合并為:
easy_install virtualenv
?參考資料:
funcscrollAtEdge(){//計算拖動視圖里邊緣的距離,正比于滾動速度,并且判斷是往上還是往下滾動letpinTop = dragView.frame.origin.yletpinBottom =self.frame.height - (dragView.frame.origin.y + dragView.frame.height)varspeed:CGFloat=0varisTop:Bool=trueifpinTop <0{? ? ? ? ? ? speed = -pinTop? ? ? ? ? ? isTop =true}elseifpinBottom <0{? ? ? ? ? ? speed = -pinBottom? ? ? ? ? ? isTop =false}else{self.timer?.invalidate()self.timer =nilreturn}ifletoriginTimer =self.timer,originSpeed = (originTimer.userInfoas? [String:AnyObject])?["speed"]as?CGFloat{//計算滾動速度和原來相差是否過大,目的是防止頻繁的創建定時器而使滾動卡頓ifabs(speed - originSpeed) >10{? ? ? ? ? ? ? ? originTimer.invalidate()NSLog("speed:\(speed)")// 60fps,滾動才能流暢lettimer =NSTimer(timeInterval:1/60.0, target:self, selector: #selector(SortableCollectionView.autoScroll(_:)), userInfo: ["top":isTop,"speed": speed] , repeats:true)self.timer = timerNSRunLoop.mainRunLoop().addTimer(timer, forMode:NSRunLoopCommonModes)? ? ? ? ? ? }? ? ? ? }else{lettimer =NSTimer(timeInterval:1/60.0, target:self, selector: #selector(SortableCollectionView.autoScroll(_:)), userInfo: ["top":isTop,"speed": speed] , repeats:true)self.timer = timerNSRunLoop.mainRunLoop().addTimer(timer, forMode:NSRunLoopCommonModes)? ? ? ? }? ? }funcautoScroll(timer:NSTimer){ifletuserInfo = timer.userInfoas? [String:AnyObject] {iflettop =? userInfo["top"]as?Bool,speed = userInfo["speed"]as?CGFloat{//計算滾動位置,更新contentOffsetletoffset = speed /5letcontentOffset =self.contentOffsetiftop {self.contentOffset.y -= offsetself.contentOffset.y =self.contentOffset.y <0?0:self.contentOffset.y? ? ? ? ? ? ? ? }else{self.contentOffset.y += offsetself.contentOffset.y =self.contentOffset.y >self.contentSize.height -self.frame.height ?self.contentSize.height -self.frame.height? :self.contentOffset.y? ? ? ? ? ? ? ? }letpoint =CGPoint(x: dragView.center.x, y: dragView.center.y + contentOffset.y)//滾動過程中,拖拽視圖位置不變,因此手勢識別代理不會調用,需要手動調用移動itemself.moveItemToPoint(point)? ? ? ? ? ? }? ? ? ? }? ? }