У меня есть мнение: DragView и вид: GameAreaView, и объявить GameAreaView в GameViewController.Objective C DrawRect в подвид не вызывается после того, как добавить его в супер вид и setNeedsDisplay
Проблема заключается в том, что мой пользовательский подзаголовок: DragView не рисовалRect, как и ожидалось, в супер-представлении ничего нет.
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) кадр
-(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;
}
В подвид с изображением отображается в GameAreaView, который не использовал DrawRect.
Я также пробовал использовать setNeesDisplayInRect, ничего не меняется.
Почему drawRect в DragView.m не вызывается при использовании - (id) initwithFrame? Почему это происходит? И как это исправить?
где вы назвали вид сопротивления? –
Сделайте свойство вашего вида перетаскивания и используйте [self.dragview setneedsdisplay]; –
Я вызвал его в - (void) touchesEnded: (NSSet *) затрагивает событиеEvent: (UIEvent *) – iMonkey