xcode CGRectMake。在 Swift 中不可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49605153/
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
CGRectMake. Is Unavailable In Swift
提问by Michelle
can someone help me here I am currently getting this error saying that CGRectMake is not available in Swift. I have looked at other answers on this and I am still getting a little confused. Could anyone please write me an exact answer would be much appreciated.
有人可以在这里帮助我吗我目前收到此错误,提示 CGRectMake 在 Swift 中不可用。我已经看过关于这个的其他答案,但我仍然有点困惑。任何人都可以写给我一个确切的答案将不胜感激。
scrollView.frame = CGRect(0, 0, self.view.frame.width, self.view.frame.height)
回答by leedex
CGRectMake has been deprecated. The syntax is now just CGRect. I believe the syntax change was introduced in Swift 3.
CGRectMake 已被弃用。语法现在只是 CGRect。我相信语法更改是在 Swift 3 中引入的。
Notice that the x and y together form a CGPoint, and the width and height form a CGSize. So when you say:
请注意,x 和 y 一起形成 CGPoint,宽度和高度形成 CGSize。所以当你说:
scrollView.frame = CGRect(0, 0, self.view.frame.width, self.view.frame.height)
you are putting the scrollView at the CGPoint (0,0) and giving it the same same CGSize as the width and height of the view (covering the whole view).
您将 scrollView 放在 CGPoint (0,0) 处,并赋予它与视图的宽度和高度相同的 CGSize(覆盖整个视图)。
回答by Vadlapalli Masthan
Which Swift version are you using? I think you are using Swift 3 and above.
您使用的是哪个 Swift 版本?我认为您使用的是 Swift 3 及更高版本。
CGRectMake is deprecated after Swift 3. You have to use CGRect instead of CGRectMake.
在 Swift 3 之后不推荐使用 CGRectMake。您必须使用 CGRect 而不是 CGRectMake。
let scrollView = UIScrollView()
scrollView.frame = CGRect(0,0,self.view.frame.width,self.view.frame.height)