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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51616073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:43:16  来源:igfitidea点击:

UIEdgeInsetsInsetRect' has been replaced by instance method 'CGRect.inset(by:)

iosswiftxcodeswift4.2

提问by Dustin Johnson

I made the mistake up updating my project to Swift 4.2 without waiting for pods to be updated. I have slowly updated all of my code, but there's one line that I can't seem to figure out.

我错误地将我的项目更新到 Swift 4.2,而没有等待 pod 更新。我已经慢慢更新了我的所有代码,但有一行我似乎无法弄清楚。

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

The error I receive is,

我收到的错误是,

UIEdgeInsetsInsetRect' has been replaced by instance method 'CGRect.inset(by:)

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

Any help with this would be greatly appreciated!

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

回答by Leo Dabus

The error it is pretty self explanatory. You can use it like this:

错误是不言自明的。你可以这样使用它:

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

or simply

或者干脆

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

回答by Prashant Gaikwad

Swift 4.2 and Xcode 10

Swift 4.2 和 Xcode 10

Earlier it was like this -

之前是这样的——

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

Now for swift 4.2 -

现在快速 4.2 -

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

回答by Karthickkck

UIEdgeInsets in Swift 4.2

Swift 4.2 中的 UIEdgeInsets

Earlier version

let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
            return UIEdgeInsetsInsetRect(bounds, padding)
        }

早期版本

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
let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
        return rect.inset(by: GlobalClass.language == "ar" ? paddingR : padding)
    }
let padding = UIEdgeInsets(top: 0, left: 40, bottom: 0, right: 5)
 override func textRect(forBounds bounds: CGRect) -> CGRect {
        return rect.inset(by: GlobalClass.language == "ar" ? paddingR : padding)
    }

回答by Denis Kutlubaev

This kind of issues with pods can also be solved by setting SWIFT_VERSIONfor a particular pod.

Pod 的这种问题也可以通过设置SWIFT_VERSION特定的 Pod来解决。

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