在Xcode中移动图像

时间:2012-12-08 06:25:25

标签: iphone ios xcode image gesture

我正在使用滑动手势识别器在我的iPhone应用程序中进行IBAction。我在视图中间有一个图像,当我向左滑动时,我希望图像向左移动一点,然后弹回到原来的位置,就像它被橡皮筋强行回来一样。谁能帮我这个?谢谢!

1 个答案:

答案 0 :(得分:0)

我使用过UIView animateWithDuration。我必须将它们嵌套以便进行弹跳,并为每个弹跳提供一个开始和结束帧。

这是一些非常难看的代码,这可能是最好的方法,但我不确定:

CGRect bounceUpFrameFirst = [[UIScreen mainScreen] bounds];
bounceUpFrameFirst.origin.y = bounceUpFrameFirst.origin.y - 30.0;
CGRect bounceUpFrameSecond = [[UIScreen mainScreen] bounds];
bounceUpFrameSecond.origin.y = bounceUpFrameFirst.origin.y - 15.0;
CGRect bounceUpFrameThird = [[UIScreen mainScreen] bounds];
bounceUpFrameThird.origin.y = bounceUpFrameFirst.origin.y - 10.0;
CGRect bounceDownFrame = [[UIScreen mainScreen] bounds];

[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceUpFrameFirst]; [sleepView setFrame:bounceUpFrameFirst];} completion:^(BOOL finished){[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceDownFrame]; [sleepView setFrame:bounceDownFrame];} completion:^(BOOL finished){[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceUpFrameSecond]; [sleepView setFrame:bounceUpFrameSecond];} completion:^(BOOL finished){[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceDownFrame]; [sleepView setFrame:bounceDownFrame];} completion:^(BOOL finished){[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceUpFrameThird]; [sleepView setFrame:bounceUpFrameThird];} completion:^(BOOL finished){[UIView animateWithDuration:0.1 animations:^{[wakeView setFrame:bounceDownFrame]; [sleepView setFrame:bounceDownFrame];}];}];}];}];}];}];