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对应父视图的宽度。

    其他的类似。

  • 相关阅读:
    Hologres如何支持亿级用户UV计算
    飞猪基于 Serverless 的云+端实践与思考
    高德打车构建可观测性系统实践
    程序员写好技术文章的几点小技巧
    配置审计(Config)变配报警设置
    进入中国内地第31年的麦当劳 ,为什么还能不断吸引新消费人群?
    OceanBase再破纪录!核心成员陈萌萌:坚持HTAP就是坚持我们做数据库的初心
    找出有序数组中缺失的数字
    删除值重复的结点
    想交链表----若有缘 必相见
  • 原文地址:https://www.cnblogs.com/nanoCramer/p/3192793.html
Copyright © 2011-2022 走看看