Draw line between two movable uiviews

て烟熏妆下的殇ゞ 提交于 2019-12-06 06:05:10

The problem is not where you add the observer, but what you're tying to observe -- you're using endNode as the keyPath on endNode which won't work (endNode isn't changing as you drag anyway). The property of endNode that you want to observe is the center.

You only then need to change the keyPath you're observing to "center", and change your implementation of observeValueForKeyPath:ofObject:change:context: like so,

-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if ([keyPath isEqualToString:@"center"] ) [self setNeedsDisplay];
}

I tested this by adding a pan gesture recognizer to one of the nodeViews, and the line connecting the two nodes was updated appropriately as I dragged.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!