我的UIView的子類在我的視圖控制器,通過手指觸摸繪製UIBezierPath通過的UIView的一個子類創建的對象:如何訪問一個UIViewController
#import "LinearInterpView.h"
@implementation LinearInterpView
{
UIBezierPath *path;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder])
{
[self setMultipleTouchEnabled:NO];
[self setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1.0]];
path = [UIBezierPath bezierPath];
[path setLineWidth:2.0];
// Add a clear button
UIButton *clearButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0, 10.0, 80.0, 40.0)];
[clearButton setTitle:@"Clear" forState:UIControlStateNormal];
[clearButton setBackgroundColor:[UIColor lightGrayColor]];
[clearButton addTarget:self action:@selector(clearSandBox) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:clearButton];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[[UIColor darkGrayColor] setStroke];
[path stroke];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path moveToPoint:p];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint p = [touch locationInView:self];
[path addLineToPoint:p];
[self setNeedsDisplay];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesEnded:touches withEvent:event];
}
@end
一切工作就好了這裏,但我需要訪問我的視圖控制器中手指生成的路徑並對其進行分析。當我調試代碼時,我可以在UIView中看到變量path
,它存在於我的視圖控制器中,但我無法以編程方式訪問它。有什麼方法可以訪問由子類創建的對象嗎?
是不是隻是將視圖與LinearInterpView連線以創建IB插座的事情? –
其實我已經有了UIView的IB插座。我需要訪問UIView內存在的UIBezierPath。 –
這是不可能的,我想。您可以做的最接近的事情是訪問包含具有某些變量的路徑對象的類,以便您可以用用戶定義的值重現它。 –