我正在更新一些旧代码,我有一个子类UIView(GraphView),它有以下touchesBegan代码:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point = [[touches anyObject] locationInView:self];
if ([self.grapher.gLayers pointInside:point]) {
NSLog(@"gLayer has point");
... do some stuff
}
// Draw a red dot where the touch occurred
UIView *touchView = [[UIView alloc] init];
[touchView setBackgroundColor:[UIColor redColor]];
touchView.frame = CGRectMake(point.x-5, point.y-5, 10, 10);
touchView.layer.cornerRadius = 5;
[self addSubview:touchView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[touchView setAlpha:0.0];
[UIView commitAnimations];
[touchView release];
}
我想将此代码(在GraphView.m中正常工作)移动到此视图的GraphViewController.m中,但我收到2个错误。第一个是那个
self.grapher.gLayers
生成错误,指出“在UIView类型的对象上找不到属性grapher”。我如何在viewcontroller中正确编写?我正在使用
self.view.grapher.gLayers
我得到的第二个错误是
touchView.layer.cornerRadius = 15;
错误显示在前向类对象'CALayer *''中找不到'属性'cornerRadius'。为什么这段代码在UIView中工作,而不是在viewcontroller中工作?
答案 0 :(得分:1)
grapher是您视图的属性吗?
您导入了<QuartzCore/QuartzCore.h>
吗?
修改强>
行。你是将它从GraphView 移到 GraphViewController? GraphViewController使用xib吗?您需要将视图类从UIView更改为GraphView。使用IB,选择View,然后将Custom Class更改为GraphView。