Antialiasing problem resizing a UIView
My iPhone app displays a wheel in portrait mode:
When it is rotated to landscape mode it zooms in on the top quadrant of this wheel:
The way I do this is to create a UIView (bounds: 768 x 768) to house the wheel, then:
- (void) layoutSubviews
{
UIDeviceOrientation O = [UIDevice currentDevice].orientation;
:
[self repositionWheelTo: O];
}
- (void) repositionWheelTo: (UIDeviceOrientation) O
{
BOOL is_L = UIInterfaceOrientationIsLandscape( O );
CGPoint centerPoint = CGPointFromPoint2D( centreOfRect( self.bounds ) );
float sc = 320.0 / 768.0;
if( ! isIPad() && is_L )
{
centerPoint.y += 200;
sc *= 2.0;
}
if( isIPad() )
sc = 1.0;
wvContainer.center = centerPoint;
wvContainer.transform = CGAffineTransformMakeScale( sc, sc );
}
This means it now correctly draws to fit the entire wheel just wi开发者_JAVA百科thin the screen on iPad and iPhone-portrait, and on iPhone-landscape it doubles in size.
So in iPhone-portrait, you can imagine a 768x768 square that extends around the actual device screen, and the transform is set so that the buttons only get drawn onto the middle section of it.
Arguably wasteful of memory, but right now I'm trying to keep the code manageable and I can't see a better way to do it, that lets me transition smoothly between portrait and landscape.
Problem is, it looks really mucky on iPhone-portrait. The anti-aliasing just isn't working right. you can see a clear staircase effect on the A in Am that vanishes when it is rotated to landscape.
How can I get the wheel to render at an acceptable quality in portrait mode?
You’re hitting the same issue you encountered in another one of your questions about filtering, namely that bilinear filtering cannot scale an image smaller than 50% without introducing aliasing (see the Limitations section). In the portrait-on-iPhone case, your scale factor sc
is 0.41666…, which is below that threshold.
Consider switching to a lower-resolution version of your wheel when in portrait (i.e. more closely matching the display size), possibly when you’re repositioning the wheel. If your wheel is drawn programmatically, you may be able to get UIKit to trigger the redraw for you by setting bounds
instead of transform
on your view and setting the view’s contentMode
to UIViewContentModeRedraw
.
精彩评论