UITabbar 应用程序中的方向问题

发布于 2024-10-02 23:40:12 字数 1792 浏览 4 评论 0原文

我正在开发标签栏应用程序,其中我按以下方式调用导航控制器 问题是我无法定向到横向模式。谁能告诉我我做错了什么吗?

问候, 萨蒂什

-(IBAction)click


{

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];

    UINavigationController *localNavigationContriller;

    FavouritesViewController *master;
    master = [[FavouritesViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:master];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
     [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [master release];

    NeedViewController *need;
    need = [[NeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:need];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [need release];

    DontNeedViewController *dontneed;
    dontneed = [[DontNeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:dontneed];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [dontneed release];

    tabBarController.delegate=self;
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

    [[[UIApplication sharedApplication] keyWindow] addSubview:tabBarController.view];
}

I am working on tab bar application in which i called navigation controller on following way
The problem is i cannot able to oriented to Landscape mode. can anybody please say what i went wrong?

Regards,
sathish

-(IBAction)click


{

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];

    UINavigationController *localNavigationContriller;

    FavouritesViewController *master;
    master = [[FavouritesViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:master];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
     [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [master release];

    NeedViewController *need;
    need = [[NeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:need];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [need release];

    DontNeedViewController *dontneed;
    dontneed = [[DontNeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:dontneed];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [dontneed release];

    tabBarController.delegate=self;
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

    [[[UIApplication sharedApplication] keyWindow] addSubview:tabBarController.view];
}

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

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

发布评论

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

评论(2

逆蝶 2024-10-09 23:40:12

听着,伙计,你必须在所有选项卡栏中将 shouldrotate 函数重写为 YES,就像你的应用程序中有 3 个选项卡栏一样,转到相应的类以及

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.

    return YES;
}

选项卡栏的所有相应类中...希望有所帮助,如果它确实为我祈祷......

Listen dude u you have to override the shouldrotate function to YES in all the tab bar , like you have 3 tab bar in your app , go to there respective class and

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.

    return YES;
}

in all the respective class of the tab bar... hope that help , if it does pray for me ...

疯狂的代价 2024-10-09 23:40:12

不可能更改 tabBar 中一个视图的方向而不更改另一个视图的方向。如果指定了 TabBar,则所有子视图(选项卡)必须具有相同的方向外观。您必须在每个 ViewController 和 TabBarController 中设置方向。

因此,只需将其添加到所有选项卡栏的主控制器中,

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;

    return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

在您的情况下,要添加此代码的控制器是
FavoritesViewController,
NeedViewController &
DontNeedViewController

It's not possible to change the orientation for one view in a tabBar and not for another. If a TabBar is specified then all the subviews (tabs) must have the same orientation appearance. You must set the orientation in each ViewController and in the TabBarController.

So just add this in all the tabbar's main Controllers

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;

    return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

In your Case those controllers where this code is to be added are
FavouritesViewController,
NeedViewController &
DontNeedViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文