Screen Property - 1

来源:互联网 发布:一键排版助手 for mac 编辑:程序博客网 时间:2024/06/05 01:09

分别在竖屏和横屏中输出视图控制器中的 :Self.view   Self.view.window   UIScreen  UIApplication的相关属性值:x y width height center Frame bounds

注意:UIDevice没有任何关于屏幕尺寸的属性,所以不添加测试,因为要用到横屏竖屏,所以用Masonry下的autolayout来实现布局:

#import "Masonry.h"#import "LBSreenPropertyTestController.h"@interface LBSreenPropertyTestController ()@end@implementation LBSreenPropertyTestController- (void)viewDidLoad{    [super viewDidLoad];    [self.view setBackgroundColor:[UIColor whiteColor]];        /**     *  本例子分别输出view, window, UIScreen, UIApplication 等(有待补充,  UIDevice无任何尺寸相关属性,只有方向)     *  的x y width height center bounds frame 值     */    UIButton* button0 = [UIButton buttonWithType:UIButtonTypeCustom];    [button0 setBackgroundColor:[UIColor redColor]];    [button0 setTitle:@"0击" forState:UIControlStateNormal];    [button0 addTarget:self action:@selector(buttonClicked:)      forControlEvents:UIControlEventTouchUpInside];    [button0 setTag:1000];    button0.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:button0];        UIButton* button1 = [UIButton buttonWithType:UIButtonTypeCustom];    [button1 setBackgroundColor:[UIColor blueColor]];    [button1 setTitle:@"1击" forState:UIControlStateNormal];    [button1 addTarget:self action:@selector(buttonClicked:)      forControlEvents:UIControlEventTouchUpInside];    [button1 setTag:1001];    button1.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:button1];        UIButton* button2 = [UIButton buttonWithType:UIButtonTypeCustom];    [button2 setBackgroundColor:[UIColor greenColor]];    [button2 setTitle:@"2击" forState:UIControlStateNormal];    [button2 addTarget:self action:@selector(buttonClicked:)      forControlEvents:UIControlEventTouchUpInside];    [button2 setTag:1002];    button2.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:button2];        UIButton* button3 = [UIButton buttonWithType:UIButtonTypeCustom];    [button3 setBackgroundColor:[UIColor grayColor]];    [button3 setTitle:@"3击" forState:UIControlStateNormal];    [button3 addTarget:self action:@selector(buttonClicked:)      forControlEvents:UIControlEventTouchUpInside];    [button3 setTag:1003];    button3.translatesAutoresizingMaskIntoConstraints = NO;    [self.view addSubview:button3];        UIView* superview = self.view;        CGFloat padding = 10.0;        [button0 mas_makeConstraints:^(MASConstraintMaker* make){            make.centerY.mas_equalTo(superview);        make.left.equalTo(superview).with.offset(padding);        make.right.equalTo(button1.mas_left).with.offset(-padding);        make.height.mas_equalTo(@100);        make.width.equalTo(@[button1, button2, button3]);        }];        [button1 mas_makeConstraints:^(MASConstraintMaker* make){            make.centerY.mas_equalTo(superview);        make.right.mas_equalTo(button2.mas_left).with.offset(-padding);        make.height.mas_equalTo(button0);        make.width.equalTo(@[button0, button2, button3]);            }];        [button2 mas_makeConstraints:^(MASConstraintMaker* make){            make.centerY.mas_equalTo(superview);        make.height.mas_equalTo(button0);        make.width.equalTo(@[button0, button1, button3]);            }];        [button3 mas_makeConstraints:^(MASConstraintMaker* make){            make.centerY.mas_equalTo(superview);        make.height.mas_equalTo(button0);        make.left.equalTo(button2.mas_right).with.offset(padding);        make.right.equalTo(superview).with.offset(-padding);        make.height.mas_equalTo(button0);        make.width.equalTo(@[button0, button1, button2]);        }];    }- (void)buttonClicked:(UIButton*)button{    switch (button.tag)    {        case 1000:        {            NSLog(@"self.view's frame  x : %f", self.view.frame.origin.x);            NSLog(@"self.view's frame  y : %f", self.view.frame.origin.y);            NSLog(@"self.view's bounds x : %f", self.view.bounds.origin.x);            NSLog(@"self.view's bounds y : %f", self.view.bounds.origin.y);                        NSLog(@"Self.view's frame width   : %f", self.view.frame.size.width);            NSLog(@"self.view's frame height  : %f", self.view.frame.size.height);            NSLog(@"self.view's bounds width  : %f", self.view.bounds.size.width);            NSLog(@"self.view's bounds height : %f", self.view.bounds.size.height);            NSLog(@"Self.view's Frame  : %@", NSStringFromCGRect(self.view.frame));            NSLog(@"Self.view's Bounds : %@", NSStringFromCGRect(self.view.bounds));            NSLog(@"Self.view's Center : %@", NSStringFromCGPoint(self.view.center));                        break;        }                    case 1001:        {            NSLog(@"self.view window's frame x  : %f", self.view.window.frame.origin.x);            NSLog(@"self.view window's frame y  : %f", self.view.window.frame.origin.y);            NSLog(@"self.view window's bounds x : %f", self.view.window.bounds.origin.x);            NSLog(@"self.view window's bounds y : %f", self.view.window.bounds.origin.y);                        NSLog(@"Self.view window's frame width   : %f", self.view.window.frame.size.width);            NSLog(@"self.view window's frame height  : %f", self.view.window.frame.size.height);            NSLog(@"self.view window's bounds width  : %f", self.view.window.bounds.size.width);            NSLog(@"self.view window's bounds height : %f", self.view.window.bounds.size.height);                        NSLog(@"Self.view window's Frame  : %@", NSStringFromCGRect(self.view.window.frame));            NSLog(@"Self.view window's Bounds : %@", NSStringFromCGRect(self.view.window.bounds));            NSLog(@"Self.view window's Center : %@", NSStringFromCGPoint(self.view.window.center));                        break;        }                    case 1002:        {            NSLog(@"UIScreen 's bounds x : %f", [[UIScreen mainScreen] bounds].origin.x);            NSLog(@"UIScreen 's bounds y : %f", [[UIScreen mainScreen] bounds].origin.y);            NSLog(@"UIScreen 's frame x  : %f", [UIScreen mainScreen].applicationFrame.origin.x);            NSLog(@"UIScreen 's frame y  : %f", [UIScreen mainScreen].applicationFrame.origin.y);                        NSLog(@"UIScreen 's bounds width  : %f", [[UIScreen mainScreen] bounds].size.width);            NSLog(@"UIScreen 's bounds height : %f", [[UIScreen mainScreen] bounds].size.height);            NSLog(@"UIScreen 's frame width   : %f", [UIScreen mainScreen].applicationFrame.size.width);            NSLog(@"UIScreen 's frame height  : %f", [UIScreen mainScreen].applicationFrame.size.height);                        NSLog(@"UIScreen 's Frame  : %@", NSStringFromCGRect([UIScreen mainScreen].applicationFrame));            NSLog(@"UIScreen 's Bounds : %@", NSStringFromCGRect([[UIScreen mainScreen] bounds]));                        break;        }                    case 1003:        {            //UIApplication 木有任何bounds相关属性变量            NSLog(@"UIApplication's frame x : %f", [[UIApplication sharedApplication] statusBarFrame].origin.x);            NSLog(@"UIApplication's frame y : %f", [[UIApplication sharedApplication] statusBarFrame].origin.y);                        NSLog(@"UIApplication 's statusBarFrame width  : %f", [[UIApplication sharedApplication] statusBarFrame].size.width);            NSLog(@"UIApplication 's statusBarFrame height : %f", [[UIApplication sharedApplication] statusBarFrame].size.height);            NSLog(@"UIApplication 's statusBarFrame : %@", NSStringFromCGRect([[UIApplication sharedApplication] statusBarFrame]));            break;        }                    default:            break;    }}- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];    }@end

效果分别如下:

竖屏:


横屏:


下一篇详细分析结果。





0 0
原创粉丝点击