UIView frame.width大小不正确(在iOS 6设备上)

UIView frame.width大小不正确(在iOS 6设备上),ios,objective-c,iphone,uiview,ios6,Ios,Objective C,Iphone,Uiview,Ios6,我们正试图通过编程方式在iOS上的游戏主视图中添加UIView(类似FB的按钮)(*游戏是使用Unity构建的) 添加like按钮的代码: like = [[FBLikeControl alloc] init]; // Calculate position. int screenWidth = UnityGetGLViewController().view.bounds.size.width; int screenHeight = UnityGetGLViewController().vie

我们正试图通过编程方式在iOS上的游戏主视图中添加UIView(类似FB的按钮)(*游戏是使用Unity构建的)

添加like按钮的代码:

like = [[FBLikeControl alloc] init];

// Calculate position.

int screenWidth = UnityGetGLViewController().view.bounds.size.width;
int screenHeight = UnityGetGLViewController().view.bounds.size.height;

int likeWidth = like.frame.size.width;
int likeHeight = like.frame.size.height;

int xPos = screenWidth - likeWidth;
int yPos = screenHeight - likeHeight;

like.frame = CGRectMake(xPos, yPos, likeWidth, likeHeight);

[UnityGetGLViewController().view addSubview:like];
在我们测试过的大多数设备上,该功能运行良好,并将按钮显示在正确的位置(右下角)

在一些iOS设备(运行iOS 6)上,该按钮被切断。它看起来像它的帧。宽度正好等于它正确大小的0.5(一半)但只有宽度


原因可能是什么?这是iOS 6或特定设备的已知错误吗?还是我们的代码不正确?

我建议尝试使用initWithFrame:方法构造按钮,并为其提供固定的宽度和高度。 我知道这不是最好的答案,但我研究了这个类,它有一些代码,当你没有提供的时候,应该计算它的大小。这段代码中可能有bug,但我不确定

最后一点建议:您应该使用CGGeometry.h中的helper方法检索帧信息:(CGRectGetHeight(),CGRectGetWidth(),CGRectGetMinX(),CGRectGetMinY()。在我看来,在int的情况下使用CGFloat也是一个好主意。)

CGFloat screenWidth=CGRectGetWidth(UnityGetGLViewController().view.bounds);
CGFloat screenHeight=CGRectGetHeight(UnityGetGLViewController().view.bounds)
CGFloat likeWidth=CGRectGetWidth(like.frame);

CGFLoat likeHeight=CGRectGetHeight(like.frame)您看到的
width
的值是多少?您确定没有将
边界
混淆吗?