快速提问,我到处寻找答案无济于事 . 我有一个stroyboard加载tabViewController作为初始视图 . 第一个选项卡是自动选择和加载的(这就是我想要的) . 我已经以编程方式自定义了此视图的布局 . 它有一个UIImage和6个UIButtons . 我在代码中以proprotionately调整了一切 . 当ViewController加载时,它不会应用我的编程格式 . 如果我离开选项卡或选择一个按钮,然后返回ViewController正确的格式 IS 那里 . 我没有't get why it doesn' t加载我编程的格式开始 . 我通过调用函数在viewDidLoad中初始化了格式但是它仍然加载了storyboard布局 . 请指教 .
谢谢你
- (void)viewDidLoad
{
[super viewDidLoad];
[self supportedInterfaceOrientations];
[self orientationAdjust];
NSLog(@"[INFO] %@ loaded",self);
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(orientationAdjust:) name: UIApplicationDidChangeStatusBarOrientationNotification object: nil];
}
-(void)orientationAdjust
{
navHeight = self.navigationController.navigationBar.frame.size.height;
tabBarHeight = self.tabBarController.tabBar.frame.size.height;
statusBarSize = [[UIApplication sharedApplication] statusBarFrame];
screen = [[UIScreen mainScreen] bounds];
screenHeight = CGRectGetHeight(screen);
screenWidth = CGRectGetWidth(screen);
screenCenter = CGRectGetMidX(screen);
orientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationIsLandscape(orientation))
{
halfScreen = screenHeight / 2;
statusBarHeight = CGRectGetWidth(statusBarSize);
banner.frame = CGRectMake(0, statusBarHeight + navHeight - 10, screenHeight, screenWidth / 3.5);
bannerHeight = CGRectGetHeight(banner.frame);
bannerWidth = CGRectGetWidth(banner.frame);
btnKits.frame = CGRectMake(halfScreen - (screenHeight / 2.5), navHeight + statusBarHeight + bannerHeight - 10, screenHeight / 2.5, screenWidth / 8);
btnFusers.frame = CGRectMake(halfScreen - (screenHeight / 2.5), navHeight + statusBarHeight + bannerHeight + screenWidth / 8 - 10, screenHeight / 2.5, screenWidth / 8);
btnKitId.frame = CGRectMake(halfScreen - (screenHeight / 2.5), navHeight + statusBarHeight + bannerHeight + screenWidth / 4 - 10, screenHeight / 2.5, screenWidth / 8);
btnTips.frame = CGRectMake(halfScreen , navHeight + statusBarHeight + bannerHeight - 10, screenHeight / 2.5, screenWidth / 8);
btnResets.frame = CGRectMake(halfScreen , navHeight + statusBarHeight + bannerHeight + screenWidth / 8 - 10, screenHeight / 2.5, screenWidth / 8);
btnExit.frame = CGRectMake(halfScreen , navHeight + statusBarHeight + bannerHeight + screenWidth / 4 - 10, screenHeight / 2.5, screenWidth / 8);
[self setTextSize];
}
else if (UIDeviceOrientationIsPortrait(orientation))
{
statusBarHeight = CGRectGetHeight(statusBarSize);
halfScreen = CGRectGetWidth(screen) / 2;
banner.frame = CGRectMake(0, statusBarHeight + navHeight + 10, screenWidth, screenHeight / 8);
bannerHeight = CGRectGetHeight(banner.frame);
bannerWidth = CGRectGetWidth(banner.frame);
CGFloat btnHeight = (screenHeight - tabBarHeight - bannerHeight) / 8;
btnKits.frame = CGRectMake(halfScreen - (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + 10, screenWidth *.75, btnHeight);
btnFusers.frame = CGRectMake(halfScreen - (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + btnHeight + 10, screenWidth *.75, btnHeight);
btnKitId.frame = CGRectMake(halfScreen - (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + (btnHeight * 2) + 10, screenWidth *.75, btnHeight);
btnTips.frame = CGRectMake(halfScreen - (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + (btnHeight * 3) + 10, screenWidth *.75, btnHeight);
btnResets.frame = CGRectMake(halfScreen - (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + (btnHeight * 4) + 10, screenWidth *.75, btnHeight);
btnExit.frame = CGRectMake(halfScreen- (screenWidth/2.5), navHeight + statusBarHeight + bannerHeight + (btnHeight * 5) + 10, screenWidth *.75, btnHeight);
[self setTextSize];
}
}
2 回答
好的,所以我发现了问题 . 当编译器进入orientationAdjust初始构建时的方向值是UIDeviceOrientationUnknown所以我添加了
条件与我想要的格式 . 这加载了我需要的视图 .
感谢大家为我调查这个 .
尝试将translatesautoresizingmaskintconstraints设置为NO .