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?
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.