내 목숨 을 구 해 줬 어. quartz2D.

// //  MyQuartzView.m //  QuartzTest // //  Created by zenny_chen on 12-2-21. //  Copyright (c) 2012 GreenGames Studio. All rights reserved. // #import "MyQuartzView.h" // Quartz2D Core Animation #import <QuartzCore/QuartzCore.h> #import <CoreText/CoreText.h> @implementation MyQuartzView - (id)initWithFrame:(CGRect)frame {     self = [super initWithFrame:frame];     if (self) {         // Initialization code     }     return self; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - ( void )drawRect:(CGRect)rect {     // Drawing code         // Quartz     CGContextRef context = UIGraphicsGetCurrentContext();     // alpha 1     CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);     CGContextFillRect(context, CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height));         // iOS , ,     //     CGContextTranslateCTM(context, 0.0f, self.frame.size.height);     CGContextScaleCTM(context, 1.0f, -1.0f);         // Path     CGMutablePathRef path = CGPathCreateMutable();         // CGPathMoveToPoint Path     CGPathMoveToPoint(path, &CGAffineTransformIdentity, 0.0f, self.frame.size.height);     CGPathAddLineToPoint(path, &CGAffineTransformIdentity, 0.0f, 0.0f);     CGPathAddLineToPoint(path, &CGAffineTransformIdentity, self.frame.size.width * 0.125f, 0.0f);     CGPathAddLineToPoint(path, &CGAffineTransformIdentity, 0.0f, self.frame.size.height);     CGPathCloseSubpath(path);         // Path :     // kCGBlendModeDestinationIn : alpha 0,     CGContextSetBlendMode(context, kCGBlendModeDestinationIn);     // path alpha 0     CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 0.0f);         // Path Path     CGContextAddPath(context, path);     CGContextFillPath(context);         CGPathRelease(path); } @end
그리고 메 인 컨트롤 러 안의 코드 를 다시 봅 시다.
?
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58 // //  ViewController.m //  QuartzTest // //  Created by zenny_chen on 12-2-21. //  Copyright (c) 2012 GreenGames Studio. All rights reserved. // #import "ViewController.h" #import "MyQuartzView.h" #import <QuartzCore/QuartzCore.h> @interface ViewController () @end @implementation ViewController - ( void )viewDidLoad {     [super viewDidLoad];     // Do any additional setup after loading the view, typically from a nib.         //     self.view.backgroundColor = [UIColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f];         //     UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 160.0f, 160.0f)];     aView.backgroundColor = [UIColor redColor];     [self.view addSubview:aView];     [aView release];         // ,     MyQuartzView *myView = [[MyQuartzView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 160.0f, 160.0f)];         // , alpha 0     myView.backgroundColor = [UIColor clearColor];         // layer layer mask     aView.layer.mask = myView.layer;         // , myView release ,     // aView.layer.mask = myView.layer myView retain 。 } - ( void )viewDidUnload {     [super viewDidUnload];     // Release any retained subviews of the main view. } - ( BOOL )shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {     return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end

좋은 웹페이지 즐겨찾기