控制台的报错百度无果,应该是控件的上下文错误
Jul 1 10:47:47 zuoye[735] <Error>: CGContextSetLineWidth: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jul 1 10:47:47 zuoye[735] <Error>: CGContextSetStrokeColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jul 1 10:47:47 zuoye[735] <Error>: CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jul 1 10:47:47 zuoye[735] <Error>: CGContextAddLineToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Jul 1 10:47:47 zuoye[735] <Error>: CGContextDrawPath: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
代码如下:
//
// ChartViewController.m
// zuoye
//
// Created by 刘悦 on 2017/6/29.
// Copyright © 2017年 BNR. All rights reserved.
//
#import "ChartViewController.h"
#import "Quartz2d.h"
@interface ChartViewController ()
@end
@implementation ChartViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
UIButton *buttonReturn = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2-50, self.view.frame.size.height-60, 100, 50)];
buttonReturn.backgroundColor = [UIColor redColor];
[buttonReturn setTitle:@"返回" forState:UIControlStateNormal];
[buttonReturn addTarget:self action:@selector(jumpFirst) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:buttonReturn];
//绘图的区域
UIView *viewblue = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 414, 600)];
viewblue.backgroundColor = [UIColor blueColor];
[self.view addSubview:viewblue];
Quartz2d *quartzView = [[Quartz2d alloc]initWithFrame:viewblue.frame];
[self.view addSubview:quartzView];
[quartzView drawXY];
[quartzView setNeedsDisplay];
}
- (void)jumpFirst{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
quartz2d的代码如下
//
// Quartz2d.m
// zuoye
//
// Created by 刘悦 on 2017/6/29.
// Copyright © 2017年 BNR. All rights reserved.
//
#import "Quartz2d.h"
@implementation Quartz2d
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
[self drawXY];
}
- (void)drawXY{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 1.0);
[[UIColor greenColor]setStroke];
CGContextMoveToPoint(context, 50, 400);
CGContextAddLineToPoint(context, 414, 400);
CGContextStrokePath(context);
}
@end
正在回答 回答被采纳积分+1
- 参与学习 1337 人
- 提交作业 712 份
- 解答问题 1878 个
很多人都在疑问没有基础该怎么学习iOS开发?不用担心,本路径采用游戏关卡式的教学模式,并且以经典OC与最新Swift双重结合的教学内容,帮助大家快速掌握两种iOS开发语言基础,去掉“零”标签。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星