UIView alt sınıfım var ve süper görüntüde dolaşabiliyorum. Kullanıcı UIView'e self.center
dışında bir yere dokunduğunda ancak self.bounds
içinde "atlar", çünkü gerçek hareketi elde etmek için self.center
'a yeni konumu ekliyorum. Bu davranıştan kaçınmak için, kullanıcının görünümü sınırlar içinde herhangi bir yere çekmesine ve sürüklemesine izin veren bir bağlantı noktası ayarlamaya çalışıyorum.UIView katmanı için bağlantı noktası belirleme
Sorunum şu ki, yeni bağlantı noktasını (aşağıdaki kodda gösterildiği gibi) hesapladığımda hiçbir şey olmuyor, görünüm hiç değişmiyor. Diğer yandan, çapa noktasını önceden hesaplanmış bir noktaya ayarlarsam, görünümü taşıyabilirim (ama daha sonra elbette önceden hesaplanan noktaya "atlar"). Bu nasıl beklendiği gibi çalışmıyor?
Teşekkürler.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// Only support single touches, anyObject retrieves only one touch
UITouch *touch = [touches anyObject];
CGPoint locationInView = [touch locationInView:self];
// New location is somewhere within the superview
CGPoint locationInSuperview = [touch locationInView:self.superview];
// Set an anchorpoint that acts as starting point for the move
// Doesn't work!
self.layer.anchorPoint = CGPointMake(locationInView.x/self.bounds.size.width, locationInView.y/self.bounds.size.height);
// Does work!
self.layer.anchorPoint = CGPointMake(0.01, 0.0181818);
// Move to new location
self.center = locationInSuperview;
}
anchorPoint'i tam olarak anladığınızdan emin olun: http://stackoverflow.com/a/22188420/550393 – 2cupsOfTech