首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIMotionEffectGroup偏移毛刺

UIMotionEffectGroup偏移毛刺
EN

Stack Overflow用户
提问于 2014-02-25 22:51:16
回答 1查看 184关注 0票数 0

目前,当我尝试更改连接了motionGroup的UIImageView的帧时,我正在努力寻找一种方法来消除偏移毛刺。

这是添加运动效果的代码:

代码语言:javascript
复制
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];

现在,当我需要更改原点时,我会这样做:

代码语言:javascript
复制
[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”。

EN

回答 1

Stack Overflow用户

发布于 2014-02-26 03:12:39

应用变换,然后在动画完成时设置帧,而不是设置帧的动画效果,而不删除运动效果:

代码语言:javascript
复制
[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;
}];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22017720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档