繁体   English   中英

在UIView上进行平滑的帧动画

[英]Smooth frame animating on UIView

我试图通过在动画块中增加UIView的x属性来在屏幕上移动UIView。 我希望元素连续移动,所以我不能仅指定结尾x和持续时间。

这段代码有效,但是非常混乱。 在模拟器中看起来不错,但设备上却断断续续。

-(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];
}];

}

您在这里与视图动画作斗争。 您的每个动画都包含一个UIViewAnimationOptionCurveEaseInOut时序曲线。 这意味着您每隔0.05秒就会尝试提高速度,然后放慢速度,然后再切换到其他位置。

第一个也是最简单的解决方案可能是通过传递选项UIViewAnimationOptionCurveLinear更改为线性时序。

也就是说,每隔5ms制作一个新动画确实符合Core Animation的观点,使代码复杂化并损害了性能。 将其发送到您当前要放置的位置。 每当您希望它移到其他地方(即使它仍在设置动画)时,请通过选项UIViewAnimationOptionBeginFromCurrentState将其发送到新位置。 它将自动调整为新目标。 如果要重复动画或来回弹跳,请使用重复选项( UIViewAnimationOptionRepeatUIViewAnimationOptionAutoreverse )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM