ビュー: DragViewとビュー: GameAreaViewがあり、GameViewControllerでGameAreaViewを宣言します。
問題は、私のカスタム サブビュー: DragView が期待どおりに drawRect を実行しなかったことです。スーパー ビューには何も描画されません。
GameViewController.m
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
...... get touch point , but haven't use it
// Initialise a dragView when user touches in gameAreaView
DragView *agentDragger = [[DragView alloc] initWithFrame:CGRectMake(10, 10,
50, 50)];
[self.gameAreaView addSubview:agentDragger];
[[self gameAreaView] setNeedsDisplay];
}
GameAreaView.m
-(void)drawRect:(CGRect)rect {
NSLog(@"I am GameAreaView Rect!!");
}
DragView.m -(id) initwithFrame::(CGRect)frame
-(id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"1.Hi i am in if ");
}
return self;
}
- (void)drawRect:(CGRect)rect {
[MyStyleKitAgent drawAgentNodeWithFrame:_frame
longPressed:_isLongPressed
vname:_name
pressed:_isPressed];
// Test for draw lines
NSLog(@"I am in DragView");
しかし、initwithFrameをinitwithImageに変更すると
-(id) initWithImage:(UIImage *) anImage
{
self = [super initWithImage:anImage];
return self;
}
drawRect を使用していない、GameAreaView に表示された画像付きのサブビュー。
setNeesDisplayInRectも使用してみましたが、何も変わりません。
-(id)initwithFrame を使用すると、 DragView.mの drawRect が呼び出されないのはなぜですか? なぜこれが起こるのですか?そして、それを修正する方法は?