[[UIScreen mainScreen] applicationFrame]

Just explain it with code:

//  ViewController.m
#import "ViewController.h"
#define kMainScreenFrame [[UIScreen mainScreen] bounds]
#define kMainScreenWidth kMainScreenFrame.size.width
#define kMainScreenHeight (kMainScreenFrame.size.height-20)
#define kApplicationFrame [[UIScreen mainScreen] applicationFrame]
#define kApplicationBounds CGRectMake(0, 0, kMainScreenFrame.size.width, kApplicationFrame.size.height) 
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    NSLog(@"[[UIScreen mainScreen] bounds]:  %f  %f  %f  %f", kMainScreenFrame.origin.x, kMainScreenFrame.origin.y, kMainScreenFrame.size.width, kMainScreenFrame.size.height);
    NSLog(@"[[UIScreen mainScreen] applicationFrame]:  %f  %f  %f  %f", kApplicationFrame.origin.x, kApplicationFrame.origin.y, kApplicationFrame.size.width, kApplicationFrame.size.height);
    NSLog(@"kApplicationBounds:  %f  %f  %f  %f", kApplicationBounds.origin.x, kApplicationBounds.origin.y, kApplicationBounds.size.width, kApplicationBounds.size.height); 
    /** if exists statusBar, output:
        [[UIScreen mainScreen] bounds]:  0.000000  0.000000  320.000000  480.000000
        [[UIScreen mainScreen] applicationFrame]:  0.000000  20.000000  320.000000  460.000000
        kApplicationBounds:  0.000000  0.000000  320.000000  460.000000
     
        if not exists statusBar, output:
        [[UIScreen mainScreen] bounds]:  0.000000  0.000000  320.000000  480.000000
        [[UIScreen mainScreen] applicationFrame]:  0.000000  0.000000  320.000000  480.000000
        kApplicationBounds:  0.000000  0.000000  320.000000  480.000000
     
        So, [[UIScreen mainScreen] bounds] have no any connection with statusBar
     */

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -20, 320, 80)];
    // 如果有statusBar, 即使是加在window上也不能遮挡住statusBar
    [view setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:view];
    UIWindow *window = [[UIWindow alloc] initWithFrame:CGRectMake(0, -20, kMainScreenWidth, kMainScreenFrame.size.height)];   // kMainScreenFrame
    [window addSubview:view];
    [window makeKeyAndVisible];
}

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iOS 获取屏幕刷新率可以通过Core Animation框架中的CADisplayLink类实现。CADisplayLink是一个定时器类,可以监听屏幕的刷新频率,并在每一帧结束时发送回调。 首先需要创建一个CADisplayLink对象,并添加到主运行循环中: ``` CADisplayLink *displayLink = [UIScreen mainScreen].maximumFramesPerSecond == 0 ? [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTick:)] : [UIScreen mainScreen].linkWithPreferredFramesPerSecond == 0 ? [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTick:)] : [UIScreen mainScreen].linkWithPreferredFramesPerSecond == 60 ? [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTick60fps:)] : [UIScreen mainScreen].linkWithPreferredFramesPerSecond == 120 ? [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTick120fps:)] : [UIScreen mainScreen].linkWithPreferredFramesPerSecond == 90 ? [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTick90fps:)] : nil; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; ``` 然后实现对应的回调方法,在每帧结束时获取屏幕的刷新率: ``` - (void)displayLinkTick:(CADisplayLink *)link { CGFloat frameInterval = link.duration/60.0; screenRefreshRate = (int)(1.0/frameInterval); } ``` 最后需要注意的是,在iOS 10之后,为了省电和减少GPU负担,屏幕刷新率可能会动态调整,因此获取到的屏幕刷新率并不一定是恒定的。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值