目前,当我尝试更改连接了motionGroup的UIImageView的帧时,我正在努力寻找一种方法来消除偏移毛刺。
这是添加运动效果的代码:
UIInterpolatingMotionEffect *xAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
xAxis.minimumRelativeValue = @(-25.0);
xAxis.maximumRelativeValue = @(25.0);
self.motionGroup = [[UIMotionEffectGroup alloc] init];
self.motionGroup.motionEffects = @[xAxis];
[self.backImageView addMotionEffect:self.motionGroup];现在,当我需要更改原点时,我会这样做:
[self.backImageView removeMotionEffect:self.motionGroup];
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.backImageView.frame;
frame.origin.x = self.originalBackImageViewOffset.x + 40;
self.backImageView.frame = frame;
} completion:^(BOOL finished) {
self.originalBackImageViewOffset = self.backImageView.frame.origin;
[self.backImageView addMotionEffect:self.motionGroup];
}];这样,如果设备倾斜,就会出现小故障。它紧跟在removeMotionEffect之后:当imageView转换到它的原始状态时,框架才会发生变化。如果手机没有倾斜,你甚至看不到故障(在模拟器中)。
如果你不移除animationGroup,那么还有一个更大的问题是你在动画过程中倾斜手机。
有人知道如何克服这个问题吗?
附注:我没有足够的名气来创建标签"UIMotionEffectGroup“或"UIMotionEffect”。
发布于 2014-02-26 03:12:39
应用变换,然后在动画完成时设置帧,而不是设置帧的动画效果,而不删除运动效果:
[UIView animateWithDuration:0.3 animations:^{
self.backImageView.transform = CGAffineTransformMakeTranslation(40, 0);
} completion:^(BOOL finished) {
CGRect frame = self.backImageView.frame;
frame.origin.x = self.originalBackImageViewOffset.x + 40;
self.backImageView.frame = frame;
self.originalBackImageViewOffset = self.backImageView.frame.origin;
}];https://stackoverflow.com/questions/22017720
复制相似问题