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) } } }