私が持っているもの:
を動かすとUIView
、次のようにしてその動きを検出しています。
[myView.layer addObserver:self forKeyPath:@"position" options:NSKeyValueObservingOptionNew context:nil];
私は動いていmyView
て、クラスが持っているさまざまな位置を検出する必要があります。UIView
self
UIView
問題:
myView
別の中に入れてUIView
移動するとanotherView
:
[anotherView addSubview: myView];
メソッド:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
理論上myView
は同様に動いていますが、もう呼び出されません。NSNotification
「動き」が発生するたびに発射されるようにしようとしましたが、不器用です。この種の問題に対する「エレガントな」解決策はありますか?
の移動には、次のUIView
メソッドを使用しています。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;