iphone - 无法在 UIView 中制作流畅的动画

标签 iphone objective-c ios uiviewanimation uianimation

我在单击按钮时向 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/

相关文章:

Iphone:无法从 UITabBarController 加载模态视图

iphone - 如何静音 AVCaptureDevice?

objective-c - "Modern"Objective-C 中的综合和 protected 实例变量?

ios - UIScrollView 检测用户点击

ios - Mapbox iOS SDK - visibleFeaturesAtPoint 返回空数组

iphone - 使用核心数据进行存储 - 在基于导航和基于窗口的应用程序中 - iPhone

iphone - 在 iOS 中解析 XML/'screen scraping' 的最佳方法是什么? UIWebview 还是 NSXMLParser?

iOS 代码 : How to load a value from a user-defined setting from build settings at run time

ios - 如何在 didReceiveRemoteNotification 中获取 userInfo JSON 值

ios - 使用导航 Controller 处理数据持久性/流的正确方法?