屏幕适配AutoResizing

适配器简介

AutoResizing

屏幕适配的历史

-iPhonestyGS\IPhone4

-没有屏幕适配可言

-全部用frame,bounds,center进行布局

-很多重要的现象:坐标值,宽度,高度全度写死


以前的屏幕适配
objc
UIButton *btn=[][UIButton alloc]init];
btn.frame=CGRectMake(0,0,320-b,480-b);



-iPad,iPhone横屏

-Autoresizing

-横竖屏幕适配相对简单


-让子控件可以跟随父控件行为自动发生相应的变化


-前提关闭auto layout


-局限性

  -只能解决子控件和父控件的相对关系
  
  -不能解决兄弟控件的相互关系
@interface ViewController ()

/**  父控件  */
@property(nonatomic,strong)UIView * blueView ;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
 
    UIView *blueView=[[UIView alloc]init];
    blueView.backgroundColor=[UIColor blueColor];
    blueView.frame=CGRectMake(0, 0, 250, 250);
    [self.view  addSubview:blueView];
    self.blueView=blueView;
    
    
    UIView *redView=[[UIView alloc]init];
    redView.backgroundColor=[UIColor redColor];
    redView.frame=CGRectMake(0, 150, 250, 100);
    redView.autoresizingMask=
    UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleWidth  ;
    [blueView addSubview:redView];
    /**
     enum {
     UIViewAutoresizingNone                 = 0,
     UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
     UIViewAutoresizingFlexibleWidth        = 1 << 1,
     UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
     UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
     UIViewAutoresizingFlexibleHeight       = 1 << 4,
     UIViewAutoresizingFlexibleBottomMargin = 1 << 5
     };
     */
}

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


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    CGFloat h=200+arc4random_uniform(100);
    CGFloat w=200+arc4random_uniform(100);
    
    self.blueView.frame=CGRectMake(0, 0, w, h);
}

@end



你可能感兴趣的:(屏幕适配AutoResizing)