某些应用程序在拖动图像时会出现“阻力”。从原点拖动图像越远,可拖动的越少。 我该如何实现此功能?
答案 0 :(得分:0)
如何对UIImageView
进行子类化并执行类似下面的操作:(不完美,但可能会出现这样的情况吗?)
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
CGPoint currentPosition = [[touches anyObject] locationInView:self.superview];
CGFloat dx = currentPosition.x - initialCentre.x;//delta x with sign
CGFloat dy = currentPosition.y - initialCentre.y;//delta y with sign
CGFloat distance = sqrt(dx*dx + dy*dy);//distance
CGFloat weightedX = initialCentre.x + dx * (1/log(distance)); //new x as inverse function of distance
CGFloat weightedY = initialCentre.y + dy * (1/log(distance)); //new y as inverse function of distance
self.center = CGPointMake(weightedX, weightedY);//set the center
}