iOS [UIApplcation sharedApplication].keyWindow.bounds 值为全0

在取keyWindow的值时,由于keyWindow 是实时变化的,其值可能为0,用[UIScreen mainScreen].bounds 即可。

[UIScreen mainScreen].bounds vs [UIApplcation sharedApplication].keyWindow.bounds?

I have view that i want to cover entire screen. And i want to set its frame to cover entire screen. Browsing the stack overflow i found these two different ways of setting view frame to cover the screen:

[UIScreen mainScreen].bounds
[UIApplcation sharedApplication].keyWindow.bounds

It seems to me they are returning same values always, or at least in few test cases I have tried.

Currently i am using UIScreen, but i curious to know difference between these calls? Will there be some cases where they will return different values?

The methods are slightly different. [UIScreen mainScreen] returns the devices UIScreen object, the bounds of this will always be the size of the devices screen. [UIApplication sharedApplication].keyWindow returns the current key UIWindow for the application, which could conceivably not be the full size of the devices screen.

Another obvious case where these could differ is if the device is attached to multiple screens. In this case, [UIScreen mainScreen].bounds will always return the devices screen size, but the key window could be on one of the other screens, and it will have a completely different size, depending on what kind of screen it is attached to.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值