开发者

How to resize (shrink) a UIView without pixellation?

In my app, I'm creating a full-screen view and then shrinking it down (to about 1/10th of its original size) so that I can later animate it to full-size. The problem is that the view looks terrible at that size, and is highly pixellated.

Here's the full-size view:开发者_如何学C

How to resize (shrink) a UIView without pixellation?

And here's the shrunken view in-place:

How to resize (shrink) a UIView without pixellation?

I'm shrinking the view using setFrame: - is there some way to tell iOS to use high-quality interpolation? Or am I already getting the highest-quality interpolation and this is the best it can do?


I'd recommend turning the view into an image before you shrink it (I assume currently you have your day view, made up of lots of subviews, which you then just shrink by adjusting the frame).

If you look you'll see this is how Apple achieve it: rather than literally shrinking the view, they will capture the contents of the view as an image, replace the view with that image, and then shrink the image. You'd do this for a number of reasons: efficiency (you can get rid of the shrunken views and replace them with a single UIImageView), speed, and also quality.

To save your UIView as an image you should do something like:

UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

...then replace your view with the image, and shrink it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜