调整 UIView 大小时的抗锯齿问题
我的 iPhone 应用程序在纵向模式下显示滚轮:
当它旋转到横向模式时,它会放大到该轮子的上象限:
我这样做的方法是创建一个 UIView (边界:768 x 768)来容纳轮子,那么:
- (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 );
}
这意味着它现在可以正确地绘制以适合 iPad 和 iPhone 纵向屏幕上的整个滚轮,而在 iPhone 横向上它的大小加倍。
因此,在 iPhone 肖像中,您可以想象一个围绕实际设备屏幕延伸的 768x768 正方形,并且设置变换以便按钮仅绘制到其中间部分。
可以说浪费了内存,但现在我正在努力保持代码的可管理性,而且我看不到更好的方法来做到这一点,这让我可以在纵向和横向之间平滑过渡。
问题是,它在 iPhone 肖像上看起来真的很脏。抗锯齿功能无法正常工作。您可以看到 Am 中的 A 上有明显的楼梯效果,当旋转到横向时该效果消失。
如何让滚轮在纵向模式下以可接受的质量渲染?
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 within 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的问题与您在另一有关过滤的问题,即双线性过滤无法在不引入的情况下将图像缩放到小于50%别名(请参阅限制部分)。在 iPhone 上的纵向情况下,比例因子
sc
为 0.41666…,低于该阈值。考虑在纵向模式下切换到较低分辨率版本的滚轮(即更接近地匹配显示尺寸),可能是在重新定位滚轮时。如果您的轮子是以编程方式绘制的,您可以通过在视图上设置
bounds
而不是transform
并设置视图的来让 UIKit 为您触发重绘contentMode
到UIViewContentModeRedraw
。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 oftransform
on your view and setting the view’scontentMode
toUIViewContentModeRedraw
.