Iphone:获取当前视图尺寸或屏幕尺寸 [英] Iphone: Get current view dimensions or screen dimensions
问题描述
您好我想获得主视图的宽度和高度。我想在横向或纵向模式下使用正确的值。我尝试了以下内容:
Hello i want to get the width and height of my main view. I want the correct value in landscape or portrait mode. I've tried the following:
NSLog(@"aaa %f", [UIScreen mainScreen].applicationFrame.size.width);
NSLog(@"zzz %f", self.view.frame.size.width);
这些在横向模式下为300,在纵向模式下为320,是的在纵向模式下更大。所以..我的视图占据整个屏幕( - 状态栏)所以我希望在横向模式下为480,在纵向模式下为320。其余的像素发生了什么。我是否需要对这些值进行硬编码?谢谢。
These give 300 in landscape and 320 in portrait mode, yes it is larger in portrait mode. So.. my view takes up the whole screen (- status bar) so I expect 480 in landscape mode and 320 in portrait mode. What happened to the rest of the pixels. Do I have to hardcode these values? Thanks.
推荐答案
以下任一行是否适合您?
Do either of the following lines work for you?
[[UIScreen mainScreen] bounds].size.height
[[UIScreen mainScreen] bounds].size.width
我想你可以减去状态栏的高度?也许我不理解你的问题
I suppose you can subtract the height of the status bar? Maybe i'm not understanding your question
这篇关于Iphone:获取当前视图尺寸或屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!