我有一个helloController,它是一个UIViewController,如果我旋转设备,我希望它改变它来加载一个新的笔尖“helloHorizontal.xib”,我该怎么办?谢谢。
答案 0 :(得分:1)
你可以这样,(我没有方便的xcode所以这段代码可能不完全准确)
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)){
WhatYourNewViewClassISCAlled* newView = [[WhatYourNewViewClassISCAlled alloc] initWithNibName:@"NIBNAME" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:newView animated:YES];
}
答案 1 :(得分:1)
我相信这是正确的方法。我在我的应用程序中使用它并且它完美地运行
(NB stackoverflow.com在这里要求这句话 - 代码格式化程序中存在错误)
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if( UIInterfaceOrientationIsLandscape(toInterfaceOrientation) )
{
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@-landscape", NSStringFromClass([self class])] owner:self options:nil];
[self viewDidLoad];
}
else
{
[[NSBundle mainBundle] loadNibNamed:[NSString stringWithFormat:@"%@", NSStringFromClass([self class])] owner:self options:nil];
[self viewDidLoad];
}
}