iPhone 无法在 TabBar 控制器中旋转视图

发布于 2024-09-06 07:43:20 字数 1082 浏览 6 评论 0原文

我正在开发一个由 TabBar 控制器组成的应用程序。 在其选项卡中,我有一个 UITableViewController 的子类,在此列表中,我在第一个单元格中有一个 Core-plot 图形,在接下来的 4 个单元格中有一些其他数据。 当我在 shouldAutorotateToInterfaceOrientation 方法中返回 YES 时,我希望列表视图会自动调整大小,但是......什么也没有。 当我在 willRotateToInterfaceOrientation 方法中添加一些日志时,它们不会显示。 有什么我错过的吗? 多谢, 吕克

// 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);
} 
}

I am working on an application that consists of a TabBar controller.
Within on of its tab, I have a subclass of UITableViewController, within this list I have a Core-plot graph in the first cell and some other data in the 4 following cells.
When I return YES in the shouldAutorotateToInterfaceOrientation method, I would expect the autoresizing of the list view to happen, but... nothing.
When I add some log in the willRotateToInterfaceOrientation method, they are not displayed.
Is there something I missed ?
Thanks a lot,
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);
} 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬心 2024-09-13 07:43:20

是的,除非您继承 UITabBarController 并正确重写其 shouldAutorotateToInterfaceOrientation: 方法,否则它将无法工作。

请参阅我的问题和相关答案

Yes, it won't work unless you subclass UITabBarController and override its shouldAutorotateToInterfaceOrientation: method correctly.

See my question here and related answers.

顾挽 2024-09-13 07:43:20
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;
}
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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文