-1
我更新一些舊的代碼,我有一個子類的UIView(GraphView)具有以下的touchesBegan代碼:的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工作正常。米)到這個視圖的GraphViewController.m,但我得到2錯誤。首先是
self.grapher.gLayers
產生一個錯誤,說的「財產圖示器的類型的UIView對象未找到。」我怎樣才能在視圖控制器中正確地編寫它?我目前使用
self.view.grapher.gLayers
我得到第二個錯誤是上線
touchView.layer.cornerRadius = 15;
錯誤說「財產‘cornerRadius’不能在正向類對象中找到‘的CALayer *’」 。爲什麼這個代碼可以在UIView中工作,而不是在viewcontroller中工作?
是grapher是視圖的屬性。導入QuartzCore修復了第二個問題 – Frank 2012-02-08 18:26:16
您的視圖控制器需要有一個名爲GraphView的自定義UIView。看到我上面的編輯。 – bbarnhart 2012-02-08 18:49:39