2015-07-13 41 views
-1

我想让我的uiimageview在水平方向上移出一条直线,然后再从另一边开始循环......这是我在swift中的代码.. 并想知道如果有人知道我可以如何在目标c中实现它?动画UIImage在objective-c

let carSpeed = 20.0/Double(view.frame.size.width) 
let duration: NSTimeInterval = Double(view.frame.size.width - car.frame.origin.x) * carSpeed 
UIView.animateWithDuration(duration, delay: 0.0, options: .CurveLinear, animations: 
          { 
           car.frame.origin.x = self.view.bounds.size.width 
          }, completion: {_ in 
           //reset cloud 
           car.frame.origin.x = -self.carImageView.frame.size.width 
           self.animateCars(car) 

如果有人知道任何有关客观C动画的教程!谢谢!

回答

0

这是您的确切的代码转换为目标C:

double carSpeed = 20.0/self.view.frame.size.width; 
NSTimeInterval duration = (self.view.frame.size.width - car.frame.origin.x) * carSpeed; 

[UIView animateWithDuration:duration 
         delay:0.0 
        options:UIViewAnimationOptionCurveLinear 
       animations:^{ 
        car.frame = CGRectMake(self.view.bounds.size.width, 
              car.frame.origin.y, 
              car.frame.size.width, 
              car.frame.size.height); 
       } 
       completion:^(BOOL finished) { 
        if (finished) { 
         car.frame = CGRectMake(-self.carImageView.frame.size.width, 
               car.frame.origin.y, 
               car.frame.size.width, 
               car.frame.size.height); 
         [self animateCars:car]; 
        } 
       }]; 
+0

谢谢!这工作! –

1

您可以设置图像视图第一的帧

UIImageView * imageView=[[UIImageView alloc]initWithFrame(x,y,width,height)]; 

然后,在以下的方法设置帧

int moveValue=10 // add your desired value 

[UIView animateWithDuration:0.25 animations:^{ 
imageView.frame=CGRectMake(x+moveValue,y,width,height); 
} completion:nil]; 
+0

这仍然没有工作/ ... int moveValue = 10; //添加你想要的值 [UIView animateWithDuration:0.25动画:^ {0} {CloudImage.frame = CGRectMake cloudImage.frame.size.height); } completion:nil]; –

+0

dispatch_async(dispatch_get_main_queue(),^ { //在此处添加您的代码 }); –