0

我在 iOS 中显示控制中心时遇到问题,我一直在搜索有关此问题的一些文档,但找不到答案。有没有办法通过单击 UIButton 使控制中心出现?

4

1 回答 1

0

您可以以编程方式将约束应用于特定的 UI 元素(链接到 iOS 开发人员文档

示例代码,例如:

// Center horizontally
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:viewToBeCentered
                                                      attribute:NSLayoutAttributeCenterX
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeCenterX
                                                     multiplier:1.0
                                                       constant:0.0]];

// Center vertically
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:viewToBeCentered
                                                      attribute:NSLayoutAttributeCenterY
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self.view
                                                      attribute:NSLayoutAttributeCenterY
                                                     multiplier:1.0
                                                       constant:0.0]];

您可以将此代码包含在按钮的操作代码中。

希望这有助于达到预期的效果!

于 2014-12-11T07:44:19.300 回答