UIEdgeInsetsInsetRect已被实例方法CGRect.inset(by :)取代

时间:2018-07-31 14:41:13

标签: ios swift xcode swift4.2

我将项目更新到Swift 4.2时犯了一个错误,而没有等待Pod被更新。我已经慢慢更新了我的所有代码,但是似乎看不到其中的一行。

var animationRect = UIEdgeInsetsInsetRect(frame, UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding))

我收到的错误是

  

UIEdgeInsetsInsetRect'已被实例方法替换   'CGRect.inset(by:)

任何对此的帮助将不胜感激!

4 个答案:

答案 0 :(得分:52)

错误很容易解释。您可以像这样使用它:

var animationRect = frame.inset(by: UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding))

或者简单地

var animationRect = frame.insetBy(dx: padding, dy: padding)

答案 1 :(得分:10)

Swift 4.2和Xcode 10

以前是这样-

let bounds = UIEdgeInsetsEqualToEdgeInsets(view.bounds,view.safeAreaInsets)

现在可以快速使用4.2-

let bounds = view.bounds.inset(by: view.safeAreaInsets)

答案 2 :(得分:2)

Swift 4.2中的UIEdgeInsets

  

早期版本

hoverBackgroundColor
let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
            return UIEdgeInsetsInsetRect(bounds, padding)
        }
to swift 4.2 and Xcode 10

答案 3 :(得分:0)

与豆荚有关的此类问题也可以通过为特定豆荚设置SWIFT_VERSION来解决。

post_install do |installer|
  installer.pods_project.targets.each do |target|

    if ['MessageKit'].include? target.name
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '5.0'
      end
    end

  end
end
相关问题