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任何版本中都按比例显示,而不会乱。

  • 相关阅读:
    【一些思路】web和app测试的区别
    【Python】I/O和比赛的其他一些问题
    【Python】迭代器和生成器的个人理解,再讲一讲协程
    【TCP/IP】如果打不开一个网页,需要如何处理?
    DOM事件
    GASP动画的基本使用
    Velocity的使用方法
    Swiper和Swiper Animate使用方法
    DOM操作
    JavaScript函数
  • 原文地址:https://www.cnblogs.com/wrzheng/p/5360866.html
Copyright © 2011-2022 走看看