当我居中时 UIView 的内容模糊 [英] UIView's content blurry when I center it

查看:24
本文介绍了当我居中时 UIView 的内容模糊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UIView 没有整个屏幕那么大,我希望它出现在屏幕中间.我使用以下代码做到了这一点:

I have UIView that isn't big as the whole screen and I want it to appear in the middle of the screen. I did that with the following code:

    self.dialogView.center = CGPointMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height / 2.0);

不幸的是,当我这样居中时,UIView 的内容显得模糊.

Unfortunately, when I center it like that, UIView's content appears blurry.

我已经解决了这个问题:

I've fixed it with this:

    self.dialogView.center = CGPointMake(self.view.bounds.size.width / 2.0 + 0.5, self.view.bounds.size.height / 2.0);

现在 UIView 的内容显示为它应该的样子:)

Now UIView's content appears as it should :)

你能告诉我为什么内容变得模糊以及为什么我需要向左位置偏移添加 0.5 吗?

Can you tell me why that content becomes blurry and why I need to add 0.5 to the left position offset?

推荐答案

新的中心导致控件视图的原点落在半像素上,例如 { 20.5, 20.5 }.由于屏幕不能只绘制半个像素,渲染引擎试图通过尽可能地扩散图像来获得相同的效果,从而导致图像模糊.

The new center is causing the origin of the control's view to fall on a half-pixel, like { 20.5, 20.5 }. Since the screen can't draw only half a pixel, the rendering engine attempts to get the same effect by diffusing the image as best it can, resulting in blurry images.

您需要确保所有视图的来源都是整数.

You need to make sure all your views' origins are whole numbers.

这篇关于当我居中时 UIView 的内容模糊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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