0%

1
2
3
4
5
# if DEBUG
#在应用启动的时候加入下面代码,然后双击状态栏
id overlayClass = NSClassFromString(@"UIDebuggingInformationOverlay");
[overlayClass performSelector:NSSelectorFromString(@"prepareDebuggingOverlay")];
#endif

画五边形

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 画五边形
- (void)drawPentagons {
UIBezierPath *apath = ({
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineJoinStyle = kCGLineCapRound;
path.lineCapStyle = kCGLineCapRound;
path.lineWidth = 5.0;

//设置起始点
[path moveToPoint:CGPointMake(100, 0)];
//增加线条
[path addLineToPoint:CGPointMake(200, 40)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40, 140)];
[path addLineToPoint:CGPointMake(0, 40)];

//关闭路径
[path closePath];

path;
});
//根据坐标连线
[apath stroke];
}

画矩形

1
2
3
4
5
6
7
8
// 画矩形
- (void)drawRectangle {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(10, 40, 200, 100)];
path.lineWidth = 5.0;
// path.lineCapStyle = kCGLineCapRound;
// path.lineJoinStyle = kCGLineCapSquare;
[path stroke];
}

画圆和椭圆

1
2
3
4
5
6
// 画圆和椭圆
- (void)drawCircle {
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(100, 40, 200, 200)];
path.lineWidth = 5.0;
[path stroke];
}

画带指定圆角的矩形

1
2
3
4
5
6
7
8
// 画带指定圆角的矩形
- (void)drawOtherRectangle {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 40, 200, 100) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(100, 100)];
path.lineWidth = 5.0;
path.lineJoinStyle = kCGLineCapRound;
path.lineCapStyle = kCGLineCapRound;
[path stroke];
}

画圆弧

1
2
3
4
5
6
7
8
// 画圆弧
- (void)drawCircleArc {
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(100, 200) radius:100 startAngle:M_PI endAngle:M_PI / 2 clockwise: NO];
path.lineWidth = 5.0;
path.lineJoinStyle = kCGLineCapRound;
path.lineCapStyle = kCGLineCapRound;
[path stroke];
}

画贝塞尔曲线


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 画贝塞尔曲线
- (void)drawBezierArc {
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineWidth = 2.0;
path.lineJoinStyle = kCGLineCapRound;
path.lineCapStyle = kCGLineCapRound;

// 曲线1
/*
// 设置起始点
[path moveToPoint:CGPointMake(100, 300)];
// 设置结束点和控制点
[path addQuadCurveToPoint:CGPointMake(300, 300) controlPoint:CGPointMake(100, 50)];
*/

// 曲线2
// [path moveToPoint:CGPointMake(10, 100)];
// [path addQuadCurveToPoint:CGPointMake(310, 100) controlPoint:CGPointMake(150, -90)];

// 曲线3 三次贝塞尔曲线
[path moveToPoint:CGPointMake(10, 100)];
[path addCurveToPoint:CGPointMake(310, 100) controlPoint1:CGPointMake(100, -100) controlPoint2:CGPointMake(100, 400)];
[path stroke];
}

目的:

A页面push到B页面,点击B页面的按钮传值到A页面,分别用delegate和Block来实现

1.在页面B定义delegate和Block

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
importUIKit

@objcprotocolDetailedViewControllerDelegate {

@objcoptionalfuncchangeValue (value:Int) ->Void;

}

classDetailedViewController:UIViewController{
var_title:String?
vardelegate:DetailedViewControllerDelegate?
varcount:Int=0

varchangeBlock:((Int) -> ())?

overridefuncviewDidLoad() {
super.viewDidLoad()
navigationItem.title=_title
self.view.backgroundColor=UIColor.brown

weakvarweakSelf =self
letbtn =CGButton.shendInstance().createButton(frame:CGRect(), bgColor:UIColor.red, title:"按钮", superView:self.view) { (action)in
weakSelf?.count+=1
letcout = weakSelf?.count
// Block回调
if(weakSelf?.changeBlock! !=nil) {
weakSelf?.changeBlock!(cout!)
}

// 代理回调
if((weakSelf?.delegate?.changeValue) !=nil) {
weakSelf?.delegate?.changeValue!(value: cout!)
}
}

}

funcchangeValue(value:@escaping(Int) -> ()) ->Void{
self.changeBlock= value
}

}

2.在push的时候

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
moiveView.clickdidSelectItemAt{ (collection, indexPath)in
letdataModel =self._movieView.dataSource[indexPath.item]as!MovieModel
letDetailedVC =DetailedViewController()
DetailedVC.delegate=self
//Block的回调
DetailedVC.changeValue(value: { (value)in
print("blockChange\(value)")
})
DetailedVC._title= dataModel.titleasString
self.navigationController!.pushViewController(DetailedVC, animated:true)
}

// delegate的回调
funcchangeValue(value:Int) {
print("delegateChange\(value)")
}

1.创建一个NetWorkingTool单例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import UIKit
import Alamofire

class NetWorkingTool: NSObject {
static let shendInstance = NetWorkingTool()
private override init() {}
public func getData(url: String, dataBlock:@escaping (_ resData: Any) ->(), errorBlock:@escaping (_ error: Error) -> ()) -> Void {
Alamofire.request(url).responseJSON { (responseData) in
if let json = responseData.result.value {
dataBlock(json)
}else{
errorBlock(responseData.error!)
}
}
}
}

2.在ViewController发起调用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NetWorkingTool.shendInstance.getData(url: "https://www.v2ex.com/api/nodes/show.json?name=python", dataBlock: { (responseData) in
//返回的是数组
guard responseData is [String: Any] else {
let dataArray = responseData as! Array<[String: Any]>
for dict in dataArray {
print(dict["title"]!, dict["id"]!)
}
return
}
//返回的是字典
guard responseData is [String: Dictionary<String, Any>] else {
let dataArray = responseData as! Dictionary<String, Any>
for value in dataArray {
print(type(of: value))
}
return
}
}) { (error) in
print(error)
}
}
}

Python创建虚拟环境

1.通过pip安装virtualenv

`pip install virtualenv`

2.查看virtualenv 的版本

`virtualenv --version`

3.创建不同Python版本的解析器

`virtualenv -p /usr/bin/python2.7 py2
virtualenv py3`

4.启动虚拟环境

source py2/bin/activate

5.退出虚拟环境

deactivate