zoukankan      html  css  js  c++  java
  • 弹出框适配总结

    1、屏幕旋转

    显示视图时,尽量不用单一的view去实现,将view放在viewcontroller里实现,这样可以在viewController中去添加其旋转方法,实现适配屏幕旋转。

    (1)支持全部方向的旋转

    iOS6.0需要下面三个方法,代码如下:

    -(BOOL) shouldAutorotateToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation{

        return (toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown);

    }

    - (BOOL)shouldAutorotate{

        return YES;

    }

    - (NSUInteger)supportedInterfaceOrientations{

        return UIInterfaceOrientationMaskAllButUpsideDown;

    }

    (2)禁止屏幕旋转

    -  (BOOL) shouldAutorotateToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation{

        return (toInterfaceOrientation == UIInterfaceOrientationPortrait);

    }

    - (BOOL)shouldAutorotate{

        return NO;

    }

    - (NSUInteger)supportedInterfaceOrientations{

        return UIInterfaceOrientationMaskPortrait;//只支持这一个方向(正常的方向)

    }

    2、屏幕旋转基本方法
    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
        NSLog(@"视图旋转之前自动调用"); 

    - (void) willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation duration : (NSTimeInterval) duration { 
        NSLog(@"视图旋转方向发生改变时会自动调用"); 

    -(void) didRotateFromInterfaceOrientation : (UIInterfaceOrientation fromInterfaceOrientation{
        NSLog(@"视图旋转完成之后自动调用"); 

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        NSLog(@"视图旋转之前自动调用");
    }
    -(void) willAnimateRotationToInterfaceOrientation : (UIInterfaceOrientation) toInterfaceOrientation duration : (NSTimeInterval)duration{
        NSLog(@"视图旋转方向发生改变时会自动调用");
    }

    -(void) didRotateFromInterfaceOrientation : (UIInterfaceOrientation) fromInterfaceOrientation{
        NSLog(@"视图旋转完成之后自动调用");
    }

    3、旋转后调整视图大小。

    当UIView设置成自动适配屏幕(即myView.autoresizesSubviews = YES)时,当我们重新设置myView的frame时(一般屏幕旋转时我们都会重新设置view的frame),会自动调用layoutSubviers方法,我们可以在该方法中判断屏幕的方向,并调整各子view的frame。

    而设置UIView的属性autoresizingMask,可以调节其在父视图的相对位置:

    UIViewAutoResizingFlexibleLeftMargin将调整view左侧到父视图的距离。

    UIViewAutoResizingFlexibleTopMargin将调整view上侧到父视图的距离。

    UIViewAutoResizingFlexibleWidth将调整view对应父视图的宽度。

    其他的类似。

  • 相关阅读:
    用GDB调试程序(一)
    ZOJ Problem Set
    android 去除标题
    【hadoop之翊】——基于CentOS的hadoop2.4.0伪分布安装配置
    layoutSubviews总结
    用数据说话,外贸产品选择(中篇)-google趋势分析法
    Apache介绍
    浅谈android4.0开发之GridLayout布局
    Android GridView 分页加载数据
    Android TableLayout中的使用说明
  • 原文地址:https://www.cnblogs.com/nanoCramer/p/3192793.html
Copyright © 2011-2022 走看看