我想通过在动画块中增加UIView的x属性来在屏幕上移动UIView。我希望元素不断移动,因此我不能只指定结尾x并延长持续时间。UIView上的平滑帧动画
此代码有效,但非常不稳定。在模拟器中看起来不错,但在设备上起伏不定。
-(void)moveGreyDocumentRight:(UIImageView*)greyFolderView
{
[UIView animateWithDuration:0.05 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
NSInteger newX = greyFolderView.frame.origin.x + 5.0;
greyFolderView.frame = CGRectMake(newX, greyFolderView.frame.origin.y, greyFolderView.frame.size.width, greyFolderView.frame.size.height);
}
} completion:^(BOOL finished) {
[self moveGreyDocumentRight:greyFolderView];
}];
}
请参阅:http://stackoverflow.com/questions/5690141/how-to-do-a-continuous-recycling-uiview-animation – magma
如果您只是在两个位置之间来回移动,则“ UIViewAnimationOptionAutoreverse'和'UIViewAnimationOptionRepeat'为标准的'animateWithDuration:delay:options:animations:completion:'block animation将完成这项工作。将它与'UIViewAnimationOptionCurveEaseInOut'结合起来,并且“转身”过程也将顺利进行。如果您想做其他事情(例如,不在两个地点之间),请告诉我们,我们可以建议其他选择。 – Rob