zoukankan      html  css  js  c++  java
  • UI中 用单例的方法进行屏幕支配,由相对位置得到确定视图位置

    #import <UIKit/UIKit.h>

    //获取手机屏幕长和宽

    #define  ScreenHEIGHT [[UIScreen mainScreen]bounds].size.height

    #define  ScreenWIDTH [[UIScreen mainScreen]bounds].size.width

    @interface AppDelegate : UIResponder <UIApplicationDelegate>

    @property (strong, nonatomic) UIWindow *window;

    //横坐标缩放

    @property(assign,nonatomic)float autoSizeScaleX;

    //纵坐标缩放

    @property(assign,nonatomic)float autoSizeScaleY;

    @end

    --------------------------------------------------------------------------------

    #import "AppDelegate.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        AppDelegate *myDelegate=[[UIApplication sharedApplication]delegate];

        

        //iphon4屏幕高度480

        if(ScreenHEIGHT>480)

        {

            //以iphon5为例  得到屏幕比例

            myDelegate.autoSizeScaleX=ScreenWIDTH/320;

            myDelegate.autoSizeScaleY=ScreenHEIGHT/568;

            

        }else

        {

            myDelegate.autoSizeScaleX=1.0;

            myDelegate.autoSizeScaleY=1.0;

        }

        

        

        return YES;

    }

     -----------------------------------------------------------------------------------------------

    #import "ViewController.h"

    #import "AppDelegate.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake1(100, 200, 200, 44)];

        lbl.backgroundColor=[UIColor redColor];

        [self.view addSubview:lbl];

      

    }

    //内联函数

    CG_INLINE CGRect

    CGRectMake1(CGFloat x,CGFloat y,CGFloat width,CGFloat height)

    {

        CGRect rect;

        AppDelegate *appdelegate=[[UIApplication sharedApplication]delegate];

        

        rect.origin.x=x*appdelegate.autoSizeScaleX;

        rect.origin.y=y*appdelegate.autoSizeScaleY;

        

        rect.size.width=width*appdelegate.autoSizeScaleX;

        rect.size.height=height*appdelegate.autoSizeScaleY;

        

        return rect;

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

     这样显示出来的视图,无论在iphon任何版本中都按比例显示,而不会乱。

  • 相关阅读:
    基于vue-cli快速构建
    '无法将“vue”项识别为 cmdlet、函数、脚本文件或可运行程序的名称' 或 'vue不是内部或外部命令' 的解决方法
    js / ajax 成功提交后怎么跳转到另外一个页面?
    SpringMVC 拦截器不拦截静态资源的三种处理方式方法
    各种JSON的maven引用
    java版微信公众号支付(H5调微信内置API)
    阿里云MongoDB存储数据
    阿里RocketMq(TCP模式)
    Nginx 简单安装
    Redis-主从复制
  • 原文地址:https://www.cnblogs.com/wrzheng/p/5360866.html
Copyright © 2011-2022 走看看