ios - 将 UITabBar 定位在顶部

标签 ios objective-c swift uitabbar

我是 iOS 开发的初学者。我的问题是:是否可以将 UITabBar 放在顶部以及如何放置? 我无法将我的 UITabBar 放在 View 的顶部。

最佳答案

这可能吗?当然可以,但它违反了人机界面准则。

截图:

Portrait Landscape Storyboard

代码:

TabController.h:

#import <UIKit/UIKit.h>

@interface TabController : UITabBarController <UITabBarControllerDelegate>

@end

TabController.m:

#import "TabController.h"

@interface TabController ()

@end

@implementation TabController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.delegate = self;
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    [self.tabBar invalidateIntrinsicContentSize];

    CGFloat tabSize = 44.0;

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (UIInterfaceOrientationIsLandscape(orientation))
    {
        tabSize = 32.0;
    }

    CGRect tabFrame = self.tabBar.frame;

    tabFrame.size.height = tabSize;

    tabFrame.origin.y = self.view.frame.origin.y;

    self.tabBar.frame = tabFrame;

    // Set the translucent property to NO then back to YES to
    // force the UITabBar to reblur, otherwise part of the
    // new frame will be completely transparent if we rotate
    // from a landscape orientation to a portrait orientation.

    self.tabBar.translucent = NO;
    self.tabBar.translucent = YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

关于ios - 将 UITabBar 定位在顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29579992/

相关文章:

ios - 无法在 UITableViewDelegate 中触发 didSelectRowAt

ios - 圆弧错误 : cannot capture __autoreleasing variable in a block

ios - 无法将 Objective-C 片段翻译成 Swift

objective-c - UI文本域密码

ios - 容器 View 白色背景,iPad Swift 问题

ios - iOS:注册动态UTI

iphone - 如何创建一个可以从不同 View Controller 访问的 NSMutable 数组

ios - 如何在使用 Core Graphics 绘制的图像上设置辅助功能标签?

ios - 在 iOS 上检查互联网连接会抛出错误

ios - 我想查看静态表格 View 中的所有单元格,这些单元格不会出现在故事​​板的屏幕上