【发布时间】:2013-06-19 22:23:56
【问题描述】:
我使用this tutorial 为我的应用创建渐变背景。 它看起来很漂亮。但是,当我改变方向时会出现问题。
它在纵向模式下看起来不错,但在横向模式下,渐变不会覆盖整个视图。我已经上传了一个截图 -
红色是渐变,蓝色部分是默认的背景色,应该被红色渐变完全覆盖。
如何覆盖整个视图?在检测到旋转变化后,我尝试调用梯度方法,但没有成功。这是我使用的代码:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(deviceOrientationDidChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];// this is in 'viewWillAppear' method
- (void)deviceOrientationDidChangeNotification:(NSNotification*)note
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[self addBackground];
}
【问题讨论】:
-
你的 addBackground 方法是什么样的?如果您使用的是教程
gradient.frame = self.view.bounds;中的代码,请确保您的 self.view.bounds 报告了正确的边界。 -
@DavisG。当方向改变时,如何在运行时获得正确的边界?
-
This 可能会有所帮助。看来
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {方法正确地报告了横向的边界。 -
这对我来说是个新闻,但this 站点声明“在调用此方法时,基于视图(自身)边界的任何更改都不会更新。”它指的是 deviceOrientationDidChangeNotification
-
我想知道为什么更新值需要这么长时间。无论如何 viewDidLayoutSubviews 工作正常。谢谢。