我在单击按钮时向 View 添加了一个 View 动画,第一次单击时 View 将滑至右侧,第二次单击时将返回..(就像 Facebook iPhone 应用程序中一样)
但是动画不太流畅,有一些抽搐之类的。但是当它到达最终的(x,y)时,它们处于正确的位置,当 View 移动时,动画看起来不太专业。帮我纠正这个问题
还有一个问题,是否有任何方法可以使用相同的事件为下面的选项卡栏设置动画。 (您可以在图像中看到选项卡栏没有随动画移动)
在此处添加代码!
- (IBAction)ShowView:(id)sender
{
if (n==0)
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(410, 205);
[[self.view layer] addAnimation:animation forKey:@"SwitchToNoti"];
n=1;
}else
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
self.view.center = CGPointMake(160,205);
[[self.view layer] addAnimation:animation forKey:@"SwitchTohome"];
n=0;
}
最佳答案
试试这个
- (IBAction)ShowView:(id)sender {
if (n==0)
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x + 100, self.view.center.y)];
[UIView commitAnimations];
n=1;
}else
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.view setCenter:CGPointMake(self.view.center.x - 100, self.view.center.y)];
[UIView commitAnimations];
n=0;
}
关于iphone - 无法在 UIView 中制作流畅的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13486760/