Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用计时器设置视图动画_Ios_Objective C_Nstimer - Fatal编程技术网

Ios 使用计时器设置视图动画

Ios 使用计时器设置视图动画,ios,objective-c,nstimer,Ios,Objective C,Nstimer,我有一个NSTimer,我正在用物理公式将UIImageView从一个地方移动到另一个地方,对于计时器功能,我使用了NSTimer,如下所示 //Timer starting timer = [NSTimer timerWithTimeInterval:0.03 target:self selector:@selector(elapse_time) userInfo:nil repeats:YES]; [[NSRunLoop mainRunLoop] addTimer:timer forMode

我有一个
NSTimer
,我正在用物理公式将
UIImageView
从一个地方移动到另一个地方,对于计时器功能,我使用了
NSTimer
,如下所示

//Timer starting
timer = [NSTimer timerWithTimeInterval:0.03 target:self selector:@selector(elapse_time) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
elapse\u time
方法中,我移动对象,如下所示

myImageView_Object.frame = //Some CGRect value

现在我在数组中有了更多的
myImageView
\对象,我需要
setFrame
一个接一个地为数组中的所有
myImageView
\对象设置帧。我怎么能做到这一点呢?

到目前为止,你的答案只是准确地回答了你的问题,而没有试图解决你的问题

您正在移动UIView。你要设置它的位置。你这样做的频率相当高。真正做到这一点的方法是使用UIView动画。给它一个块,告诉它动画应该花费多长时间,告诉它在总时间之后应该处于什么位置。它为您提供粗花呢和展示。例如:

您希望在3秒内将UIView从其原始位置移动到某个新位置:

// Assume view1, view are UIView objects
view1.frame = // set initial frame
view2.frame = // set initial frame
view3.frame = // set initial frame

[UIView animateWithDuration:3.0 animations:^{
    view1.frame = // set final frame
    view2.frame = // ...
    view3.frame = == ...
}];
您还可以使用其他变体,并且可以在“带块的动画”下找到它们