ios – 将UITabBar定位在顶部

前端之家收集整理的这篇文章主要介绍了ios – 将UITabBar定位在顶部前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是iOS开发的初学者.我的问题是:是否可以将UITabBar置于顶部,如何?
我无法将UITabBar放置在视图的顶部.

解决方法

可能吗?当然,但是它违反了人机接口指南.

截图:

码:

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
原文链接:https://www.f2er.com/iOS/335054.html

猜你在找的iOS相关文章