老师为什么我运行后画不出红线
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // // AppDelegate.h // 锁屏 // // Created by on 2018 /10/29 . // Copyright © 2018 lzn. All rights reserved. // #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @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 | // // ViewController.m // 锁屏 // // Created by on 2018 /10/29 . // Copyright © 2018 lzn. All rights reserved. // #import "ViewController.h" #import "UnBlockView.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UnBlockView *blockView = [[UnBlockView alloc]initWithFrame:self.view.frame]; blockView.backgroundColor = [UIColor lightGrayColor]; [self.view addSubview:blockView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @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 | // // UnBlockView.m // 锁屏 // // Created by on 2018 /10/29 . // Copyright © 2018 lzn. All rights reserved. // #import "UnBlockView.h" @interface UnBlockView(); @property(nonatomic,assign) CGMutablePathRef path; @end @implementation UnBlockView -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch * touch = touches.anyObject; CGPoint pt = [ touch locationInView: touch .view]; // 判断该点是不是落在了手势点上 self.path = CGPathCreateMutable(); CGPathMoveToPoint(self.path, NULL, pt.x, pt.y); } -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ UITouch * touch = touches.anyObject; CGPoint pt = [ touch locationInView: touch .view]; CGPathAddLineToPoint(self.path, NULL, pt.x, pt.y); [self setNeedsDisplay]; } -(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ if (self.path){ CGPathRelease(self.path); self.path = nil; } } -(void)drawRect:(CGRect)rect{ if (self.path){ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGContextSetLineWidth(context, 4); CGContextDrawPath(context, kCGPathStroke); } } @end |
0
收起
正在回答 回答被采纳积分+1
1回答
iOS入门:基础语法与常用控件
- 参与学习 1337 人
- 提交作业 712 份
- 解答问题 1878 个
很多人都在疑问没有基础该怎么学习iOS开发?不用担心,本路径采用游戏关卡式的教学模式,并且以经典OC与最新Swift双重结合的教学内容,帮助大家快速掌握两种iOS开发语言基础,去掉“零”标签。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧