自定义视图与CGRectMake位置x和y提供不正确的视图

时间:2016-03-16 13:20:47

标签: ios uiview xcode7 cgrectmake

以前我使用的是Xcode 6.4或更低版本,因为我没有通知此类型的问题。但是现在我在相关的CGRectMake x,y Position中的Xcode 7.2中遇到了明显的问题。

    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    UIView *smallView=[[UIView alloc]initWithFrame:CGRectMake(screenWidth/2, screenHeight/2, 100, 100)];
    smallView.backgroundColor=[UIColor redColor];
    [self.view addSubview:smallView];
    NSLog(@"%f",smallView.frame.origin.x);// 137.500000

以上剪辑代码,x&的位置你并不完美。输出以下图像。 enter image description here

但是如果我添加center = self.view.ceter它会来到中心。输出为enter image description here

 smallView.center=self.view.center;

问题是,在x和amp; y位置值相同,

  NSLog(@"%f\n%f\n%f\f%f ",screenWidth/2,screenHeight/2,self.view.center.x,self.view.center.y);

为什么他们会显示不同的结果,我怎么能不使用中心属性。或者应该去Autolayout。

0 个答案:

没有答案