具有平铺背景图像的 UIView 旋转上的视觉伪影
我有一个带有标准 UIViewController/UIView 设置的 iPad 应用程序 - 允许所有旋转。 UIView 绘制一些平铺图像作为背景(平铺图像为 256*256 像素):
- (void)drawRect:(CGRect)rect
{
[[UIImage imageNamed: @"Background.png"] drawAsPatternInRect: rect];
}
当我转动 iPad 时,我可以看到在旋转过程中原始方向的图像图案缩放以适应新的方向方向。然后 - 动画完成后立即 - 视图使用未缩放的最终配置重绘其背景图案。从缩放模式切换到未缩放模式看起来有点难看。
有没有办法规避(或隐藏)背景图案的这种拉伸?
I have an iPad app with a standard UIViewController/UIView setup - all rotations are allowed. The UIView draws some tiled image as background (the tile is 256*256 pixels):
- (void)drawRect:(CGRect)rect
{
[[UIImage imageNamed: @"Background.png"] drawAsPatternInRect: rect];
}
When I turn my iPad I can see that during the rotation the image pattern of the original orientation is scaled to fit the new orientation. Then - immediately after the animation is finished - the view redraws its background pattern with the final configuration which is unscaled. The switching from a scaled to an unscaled pattern looks a bit ugly.
Is there a way to circumvent (or hide) this strecthing of the background pattern?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不使用图案图像作为背景“颜色”?这会自动产生平铺图案,并避免使用drawRect()的任何特技。例如:
Why not use a pattern image as background "color"? This automatically results in a tiled pattern and avoids any stunts with drawRect(). For example:
简单地说,
[myView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"Background.png"] ] ];
to put simply,
[myView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"Background.png"] ] ];