问题描述
我正在尝试在界面方向更改时根据屏幕尺寸调整某些元素的大小。我已经在不同的地方阅读过(包括这里的一些答案),获取屏幕边界的方法是使用[[UIScreen] mainScreen] bounds]。所以我已添加此代码以查看其行为:
I'm trying to make certain elements resize according to the screen dimensions when the interface orientation changes. I've read in various places (including a few answers on here) that the way to get the bounds of the screen is to use [[UIScreen] mainScreen] bounds]. So I've added this code to see how it behaves:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"view dimensions: (%@, %@)", [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
}
但是在运行它时,只要我旋转屏幕,我就会得到一个EXC_BAD_ACCESS信息。是否有一些关于willRotateToInterfaceOrientation函数的范围,它不允许我调用屏幕边界?如果是这样,我该怎么做?
But when running it, as soon as I rotate the screen I get an EXC_BAD_ACCESS message. Is there something about the scope of the willRotateToInterfaceOrientation function that doesn't allow me to call for the screen bounds? If so, how would I go about it?
推荐答案
%@ format说明符期望格式参数为objective-c对象,而你提供的是普通浮动。要打印浮点数,请使用%f
说明符:
%@ format specifier expects format parameter to be objective-c object, while what you provide is plain float. To print float numbers use %f
specifier:
NSLog(@"view dimensions: (%f, %f)", [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height);
这篇关于尝试获取iPhone屏幕尺寸时的EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!