gpt4 book ai didi

swift - 如何将 MONActivityView 方法转换为 Swift

转载 作者:行者123 更新时间:2023-11-30 10:04:47 24 4
gpt4 key购买 nike

我正在尝试使用用 Obj-C 编写的自定义 ActivityIndi​​catorView。它包含将指示器置于 UIView 框架中所需的方法。我在 Swift 代码中使用它时遇到问题。这是代码...

- (void)placeAtTheCenterWithView:(UIView *)view {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterX
multiplier:1.0f
constant:0.0f]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeCenterY
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeCenterY
multiplier:1.0f
constant:0.0f]];
}

GitHub 的链接是 https://github.com/mownier/MONActivityIndicatorView

如何在 Swift 中使用它?

最佳答案

这是您要找的吗?将 Objective-C 转换为 Swift ?如果是这样,翻译如下:

func placeAtTheCenterWithView(view: UIView) {
let xCenterConstraint = NSLayoutConstraint(item: view, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1, constant: 0)
let yCenterConstraint = NSLayoutConstraint(item: view, attribute: .CenterY, relatedBy: .Equal, toItem: self.view, attribute: .CenterY, multiplier: 1, constant: 0)
self.view.addConstraints([xCenterConstraint, yCenterConstraint])
}

干杯;)

关于swift - 如何将 MONActivityView 方法转换为 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36638529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com