【发布时间】:2012-02-08 18:15:29
【问题描述】:
我正在更新一些旧代码,并且我有一个子类 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 类型的对象上找不到属性图示器。”我将如何在视图控制器中正确编写它?我目前正在使用
self.view.grapher.gLayers
我遇到的第二个错误在线
touchView.layer.cornerRadius = 15;
错误说在前向类对象“CALayer *”中找不到“属性“cornerRadius”。为什么这段代码可以在 UIView 中运行,而在 viewcontroller 中却不行?
【问题讨论】:
标签: objective-c cocoa-touch uitouch