我正在开发一个由TabBar控制器组成的应用程序。 在它的选项卡上,我有一个UITableViewController的子类,在这个列表中我在第一个单元格中有一个核心图表,在后面的4个单元格中有一些其他数据。 当我在shouldAutorotateToInterfaceOrientation方法中返回YES时,我希望列表视图的自动调整能够发生,但是......没有。 当我在willRotateToInterfaceOrientation方法中添加一些日志时,它们不会显示。 我错过了什么吗? 非常感谢, LUC
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
NSLog(@"Orientation");
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
NSLog(@"Rotating");
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
NSLog(@"view land:%@", self.view);
}
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
NSLog(@"view portrait:%@", self.view);
}
}
答案 0 :(得分:2)
是的,除非您继承UITabBarController
并正确覆盖其shouldAutorotateToInterfaceOrientation:
方法,否则它将无效。
答案 1 :(得分:0)
add this method in category
@implementation UITabBarController(UITabBarControllerCategory)
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
if ([AppDelegate isLandScapeOnly]){
return NO;
}
return YES;
}