1

当您拖动图像时,某些应用程序具有这种“拖动阻力”。将图像从原点拖得越远,它变得越少。如何实现此功能?

4

1 回答 1

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


}
于 2013-07-05T12:02:56.440 回答