这是一个非常非常微妙的效果,但我注意到我的UIImageView图像在被拖动后变得有点模糊。
我只是使用UIPanGestureRecognizer在屏幕上移动它,并在移动时影响alpha(在拖动UI效果时使其变亮)。
有没有人知道为什么它会失去一些图像质量并变得有点模糊?
-(void)handlePan:(UIPanGestureRecognizer *)recognizer{
self.alpha = 0.7;
CGPoint translation = [recognizer translationInView:self.superview];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.superview];
//make the sprite slide on release
if (recognizer.state == UIGestureRecognizerStateEnded){
self.alpha = 1.0;
CGPoint velocity = [recognizer velocityInView:self.superview];
CGFloat magnitude = sqrtf((velocity.x * velocity.x) + (velocity.y * velocity.y));
CGFloat slideMult = magnitude/200;
float slideFactor = 0.01 *slideMult; //increase for more slide
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x *slideFactor), recognizer.view.center.y + (velocity.y * slideFactor));
finalPoint.x = MIN(MAX(finalPoint.x, 0), self.superview.bounds.size.width);
finalPoint.y = MIN(MAX(finalPoint.y, 0), self.superview.bounds.size.height);
[UIView animateWithDuration:slideFactor*2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{recognizer.view.center = finalPoint;}
completion:nil];
*编辑:我认为它与状态结束时的滑动效果有关。
答案 0 :(得分:3)
如果您的imageView.frame.origin位于(6.66666,7.55555)之类的分数上,则图像可能会模糊。这只是简单的像素对齐。
在您的平移代码中,使用CGRectIntegral对齐整数,如下所示:
panningImageView.frame = CGRectIntegral(panningImageView.frame);
如果您需要不同的舍入行为,还有其他选项,例如roundf(),ceilf()和floorf()。