UIImageView平移后会失去质量吗? [英] UIImageView loses quality after panning?

查看:52
本文介绍了UIImageView平移后会失去质量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常非常微妙的效果,但是我注意到UIImageView图像在被拖动后变得略微模糊.

This is a very, very subtle effect, but I am noticing that my UIImageView images become slightly blurry after being dragged around.

我只是使用UIPanGestureRecognizer在屏幕上移动它,并在移动它时影响alpha(在为获得UI效果而拖动时使其更亮).

I'm simply using a UIPanGestureRecognizer to move it around the screen, and affecting the alpha when it is being moved (making it lighter when dragging around for UI effect).

有人知道为什么它会丢失一些图像质量并变得有点模糊吗?

Does anyone have clues as to why it would lose some image quality and get a little blurry?

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

*我认为这与状态结束时的滑动效果有关.

* I believe it has something to do with the sliding effect when the state ends.

推荐答案

如果imageView.frame.origin位于(6.66666,7.55555)之类的分数上,则图像可能会模糊.这只是简单的像素对齐.

If your imageView.frame.origin is on a fraction like (6.66666, 7.55555) the image may blur. This is just simple pixel alignment.

在平移代码中,使用CGRectIntegral像这样对齐整数:

In your panning code, use CGRectIntegral to align to integers like so:

panningImageView.frame = CGRectIntegral(panningImageView.frame);

如果需要不同的舍入行为,还有其他选项,例如roundf(),ceilf()和floorf().

There are other options, such as roundf(), ceilf() and floorf() if you need different rounding behavior.

这篇关于UIImageView平移后会失去质量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆