のUIViewControllerでのUIViewのサブクラスにより作成されたオブジェクトにアクセスする方法:ここ指のタッチでUIBezierPathを描き、私は私のビューコントローラでのUIViewのサブクラスを持って
#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
すべてがうまく動作しますが、Iビューコントローラで指で生成されたパスにアクセスして分析する必要があります。私はコードをデバッグするとき、私は、ビューコントローラに存在するUIViewの変数path
を見ることができますが、私はそれをプログラム的にアクセスすることはできません。サブクラスによって作成されたオブジェクトにアクセスする方法はありますか?
LinearInterpViewでビューを配線接続して、IB Outletを作成するだけでは問題ありませんか? –
実際には、私はすでにIBViewをUIViewに持っていません。 UIViewの内部にあるUIBezierPathにアクセスする必要があります。 –
これは不可能だと思います。あなたができる最も近いことは、いくつかの変数を持つパスオブジェクトを含むクラスにアクセスして、ユーザー定義の値でそれを再現できるようにすることです。 –