【问题标题】:Specific Orientation Background特定方向背景
【发布时间】:2013-06-15 09:19:57
【问题描述】:
这是我在 ipad iOS6 中指定背景的代码,
- (void)viewDidLoad
{
if ([[UIScreen mainScreen] bounds].size.height == 1024)
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"homeipad.png"]];
}
else if ([[UIScreen mainScreen] bounds].size.height == 768)
{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"landscapipad.png"]];
}
}
它不会改变取决于方向?我已经包括了
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
如何在ipad中为对应的方向分配特定的背景图片?
【问题讨论】:
标签:
ipad
ios6
orientation
【解决方案1】:
记住viewDidLoad 仅在您在内存中创建一个新的UIViewController 对象并推送/呈现该控制器对象时调用。
方法名称viewDidLoad 定义您的viewcontroller 视图已加载。现在您可以在此处执行所有初始化任务。
回答您的问题。
以下 UIVIewController 的委托方法将在这方面为您提供帮助。每次设备改变方向时都会调用这些方法。
// Called before interface rotation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
// Called after interface rotation
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
还有一件事,除了比较屏幕高度之外,您还可以通过以上两种方法检查当前方向。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
// Your code goes here for landscape orientation
}
else
{
// Your code goes here for portrait orientation
}
}