一些对我来说很奇怪的问题:
- (void)horizontalPickerView:(HorizontalPickerView *)picker didSelectElementAtIndex:(NSInteger)index {
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
sdashSize = CGRectMake(0.0f, 40.0f, self.view.frame.size.width, self.view.frame.size.height);
} else {
sdashSize = CGRectMake(0.0f, 40.0f, self.view.frame.size.height, self.view.frame.size.width - 40.0f);
}
}
如您所见,我有一个选择器 View 。这个方法每次运行,我在这个选择器 View 中选择了一些东西。所以现在如果我将我的 iPhone 旋转到横向并使用此代码转到下一个 View ,它运行一次 -> 转到 if 状态并给我尺寸:320 x 480。所以现在选择相同方向的一些元素并运行相同代码(如果再次声明)给我 480 x 320。我不明白相同方向的相同代码怎么会给我不同的值。
最佳答案
不要使用 frame
属性,使用 bounds
属性。本质上:
View 的框架 (CGRect) 是其矩形在父 View 坐标系中的位置。默认情况下,它从左上角开始。
View 的边界 (CGRect) 在其自己的坐标系中表示 View 矩形。
This answer进一步深入解释正在发生的事情。
关于ios - self.view.frame.size 在同一方向改变值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24866949/