Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIButton自身位置不正确,并且在某些设备中未显示-目标C_Ios_Objective C_Iphone_Uibutton - Fatal编程技术网

Ios UIButton自身位置不正确,并且在某些设备中未显示-目标C

Ios UIButton自身位置不正确,并且在某些设备中未显示-目标C,ios,objective-c,iphone,uibutton,Ios,Objective C,Iphone,Uibutton,我试图在一个视图应用程序中将两个按钮居中对齐。我不想使用自动布局,我试图通过编程解决这个问题。因此,在我的ViewController.m中,在ViewDidLoad()函数中,我放置了以下代码: _firstButton.center = CGPointMake(self.view.center.x, self.view.frame.size.height/2.0-235); _secondButton.center = CGPointMake(self.view.center.x, _sec

我试图在一个视图应用程序中将两个按钮居中对齐。我不想使用自动布局,我试图通过编程解决这个问题。因此,在我的ViewController.m中,在ViewDidLoad()函数中,我放置了以下代码:

_firstButton.center = CGPointMake(self.view.center.x, self.view.frame.size.height/2.0-235);
_secondButton.center = CGPointMake(self.view.center.x, _secondButton.frame.size.height/2.0+(self.view.frame.size.height*0.9));
第二个按钮正确定位在任何屏幕、任何设备和任何模拟器上。第一个按钮仅在iPhone5和5S模拟器中正确定位,但在我的iPhone5c设备或iPhone6&6 Plus模拟器中甚至没有显示

我做错了什么,我错过了什么

提前谢谢


ps:objective-c noob在这里,如果在
viewDidLoad
中这是一个太愚蠢的问题,对不起,帧尚未设置。我建议您在
视图中将出现

中执行此操作,请确保这不是一个愚蠢的问题。 作为一点帮助,我可以告诉您,我发现使用主xib自动布局更容易处理布局

否则对于多个屏幕大小,您可以将大小或位置作为实际屏幕大小的相关项进行管理:
UIScreen.mainScreen()

   let screenSize: CGRect = UIScreen.mainScreen().bounds

   let sreenHeight = screenSize.height
   let screenWidth = screenSize.width

   let cardwidth = screenSize.width * 0.47
   let cardheight = screenSize.height * 0.47

   let ViewBackGround = UIView(frame:CGRectMake(0, 0, cardwidth * 0.8, cardwidth))

将代码移动到
UIViewController
-viewdilayoutsubviews
。是的,就是这样!我从没想过,谢谢你!