0

我在按钮单击时向我的视图添加了视图动画,第一次单击时视图将滑动到右侧,第二次单击时将返回..(就像在 Facebook iPhone 应用程序中一样)

但是动画不是那么流畅,有一些抽搐和所有。但是当它到达最终(x,y)时,它们处于正确的位置,当视图移动时,动画看起来并不那么专业。帮我纠正这个

还有一个问题,有没有办法用相同的事件为下面的标签栏设置动画。(您可以在图像中看到标签栏没有随动画一起移动)

在此处添加代码!

- (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;
 }
4

2 回答 2

1

试试这个

- (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;
}

}

于 2012-11-21T06:22:32.507 回答
0

您可以使用以下代码显示动画:-

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.40];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.view.frame = TestRect;
[UIView commitAnimations];

您需要在这里创建一个名为 TestRect 的 CGRect ,看看这是否能解决您的问题。

于 2012-11-21T05:58:39.387 回答