【问题标题】:iPhone development: play animation backwardsiPhone开发:倒放动画
【发布时间】:2012-08-31 14:46:53
【问题描述】:
在我的应用程序中有一个动画。当我按下按钮时,将执行动画(假设一个框从左向右移动。)并且 ViewController 由“pushViewContreller”更改。我想要的是当我从 secondViewController 使用 popViewController 时,应该打开 firstViewController 并且框应该从右向左移动(反向操作)。提前致谢。
【问题讨论】:
标签:
iphone
objective-c
ios
animation
uiviewcontroller
【解决方案1】:
在导航之前,保存盒子的开始位置和结束位置,当你回来时将盒子从END位置移动到开始位置。
【解决方案2】:
如果你想移动一个盒子,那么你可以使用这个代码。
首先让两个 CGRect 说 CGRect left 和 CGRect right。
然后在 firstViewController 的 viewWillAppear 中写下这段代码。
CGRect left = //Your left side Frame
CGRect right = //Your right side frame
if (CGRectContainsPoint(right, YourObject.center))
{
[UIView animateWithDuration:0.3 animations:^{
[YourObject setFrame:left];
}];
}
在这段代码中,viewWillAppear 会在你每次弹出 secondViewController 时调用,如果你的盒子在右边,它会制作将它向左移动的动画。
在按钮上单击编写此代码
CGRect left = //Your left side Frame
[UIView animateWithDuration:0.3 animations:^{
[YourObject setFrame:left];
}];
希望您在使用此代码后会很开心............