触摸开始位置问题
我正在更新一些旧代码,并且我有一个子类 UIView (GraphView),它具有以下 TouchBegan 代码:
- (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 中运行?
I am updating some old code and I have a subclassed UIView (GraphView) that has the following touchesBegan code:
- (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];
}
I'd like to move this code (which works fine in GraphView.m) into the GraphViewController.m for this view but I'm getting 2 errors. The first is that
self.grapher.gLayers
generates an error saying the 'Property grapher not found on object of type UIView.' How would I write this properly in the viewcontroller? I'm currently using
self.view.grapher.gLayers
The second error I'm getting is on the line
touchView.layer.cornerRadius = 15;
The error says 'Property 'cornerRadius' cannot be found in forward class object 'CALayer *''. Why would this code work in the UIView but not the viewcontroller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
grapher 是你的 view 的属性吗?
您是否导入了
?编辑
确定。您要将其从 GraphView 移至 GraphViewController 吗? GraphViewController 使用 xib 吗?您需要将视图类从 UIView 更改为 GraphView。使用 IB,选择视图,然后将自定义类更改为 GraphView。
Is grapher a property of your view?
Did you import
<QuartzCore/QuartzCore.h>
?Edit
OK. You're moving this from GraphView to GraphViewController? Does GraphViewController use a xib? You'll need to change the class of view from UIView to GraphView. With IB, select the View and then change the Custom Class to GraphView.