拖动UIImageView时泛阻力?

时间:2013-07-05 07:20:20

标签: ios objective-c

某些应用程序在拖动图像时会出现“阻力”。从原点拖动图像越远,可拖动的越少。 我该如何实现此功能?

1 个答案:

答案 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


}