objective-c 中的 UIImage 动画
animate UIImage in objective-c
我正在尝试让我的 uiimageview 沿直线水平移动到边界外并从另一侧开始再次循环...这是我在 swift..
想知道是否有人知道我如何在 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)
如果有人知道任何关于 objective C 动画的教程!谢谢!
您可以先设置图片视图的边框
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];
这是您转换为 Objective-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];
}
}];
我正在尝试让我的 uiimageview 沿直线水平移动到边界外并从另一侧开始再次循环...这是我在 swift.. 想知道是否有人知道我如何在 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)
如果有人知道任何关于 objective C 动画的教程!谢谢!
您可以先设置图片视图的边框
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];
这是您转换为 Objective-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];
}
}];