【发布时间】:2011-05-18 02:52:57
【问题描述】:
我有这个具有不同 NIB 和视图的 iPad 应用程序。 每个视图都有两个 NIB,一个用于纵向,一个用于横向,所以我正在寻找一种方法来以编程方式为给定的 UIViewController 切换 NIB。
现在我在每个控制器的 willRotateToInterfaceOrientation 方法中使用了这个函数:
void UIHandleRotation( UIViewController *controller, NSString *nibName, UIInterfaceOrientation orientation, BOOL transform ){
double angle = 0.0;
if( orientation == UIInterfaceOrientationPortrait ) {
angle = PI * 2 /* 360° */;
}
else if( orientation == UIInterfaceOrientationLandscapeLeft ){
angle = PI + PI/2 /* 270 ° */;
// Each landscape nib is [nib-name]L
nibName = [NSString stringWithFormat:@"%@L", nibName];
}
[[NSBundle mainBundle] loadNibNamed:nibName owner:controller options:nil];
if( transform ) {
controller.view.transform = CGAffineTransformMakeRotation( angle );
}
}
但它给了我奇怪的行为(ui 控件位置混乱,插座没有像在界面生成器中那样关联,等等)。
我做错了什么还是有更好的方法来实现它? 谢谢
注意:我没有使用导航控制器,所以我不能使用这个解决方案Easiest way to support multiple orientations? How do I load a custom NIB when the application is in Landscape?
【问题讨论】:
标签: interface-builder ipad orientation rotation