| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // UIViewController+Layout.m
- // CommonLibrary
- //
- // Created by Alexi on 3/13/14.
- // Copyright (c) 2014 Alexi. All rights reserved.
- //
- #import "UIViewController+Layout.h"
- #import "IOSDeviceConfig.h"
- @implementation UIViewController (AsChild)
- - (void)setAsChild:(BOOL)asChild
- {
-
- }
- - (BOOL)asChild
- {
- return NO;
- }
- - (void)setChildSize:(CGSize)childSize
- {
-
- }
- - (CGSize)childSize
- {
- return CGSizeZero;
- }
- @end
- @implementation UIViewController (Layout)
- - (BOOL)shouldAutorotate
- {
- BOOL isPad = [IOSDeviceConfig sharedConfig].isIPad;
- if (isPad)
- {
- [self layoutSubviewsFrame];
- }
- return isPad;
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
- {
- return [self shouldAutorotate];
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskAll;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- {
- return UIInterfaceOrientationPortrait;
- }
- - (void)layoutOnIPhone
- {
- // iPhone上的布局
- }
- - (void)layoutOnIPadInPortrait
- {
- // iPad竖屏布局
- [self layoutOnIPhone];
- }
- - (void)layoutOnIPadInLandScape
- {
- // iPad横屏布局
- [self layoutOnIPhone];
- }
- - (void)layoutSubviewsFrame
- {
- if (CGRectIsEmpty(self.view.bounds))
- {
- return;
- }
-
- // App 根据需求决定如何进行布局
- IOSDeviceConfig *app = [IOSDeviceConfig sharedConfig];
- if (app.isIPad)
- {
- if (app.isPortrait)
- {
- [self layoutOnIPadInPortrait];
- }
- else
- {
- [self layoutOnIPadInLandScape];
- }
- }
- else
- {
- [self layoutOnIPhone];
- }
- }
- - (void)layoutOnViewWillAppear
- {
- [self layoutSubviewsFrame];
- }
- - (void)addOwnViews
- {
- // 此处添加界面中的控件
- }
- - (void)configOwnViews
- {
- // 此处配置界面中的控件的值
- }
- @end
- @implementation UITabBarController (Layout)
- - (BOOL)shouldAutorotate
- {
- return [self.selectedViewController shouldAutorotate];
- }
- @end
|