Ios 如何实现在CGRect';斯威夫特怎么样?
我正试图有一个可滚动的应用程序,现在我有多个CGRect的正在创建的功能为在。一旦它们都被创建和布局,它们就超过了屏幕视图,但它们是静态的,我无法向下滚动查看其余的。这是我的密码:Ios 如何实现在CGRect';斯威夫特怎么样?,ios,swift,scroll,Ios,Swift,Scroll,我正试图有一个可滚动的应用程序,现在我有多个CGRect的正在创建的功能为在。一旦它们都被创建和布局,它们就超过了屏幕视图,但它们是静态的,我无法向下滚动查看其余的。这是我的密码: import UIKit class Draw2dD: UIView { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) //measuring the screen size let scree
import UIKit
class Draw2dD: UIView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
//measuring the screen size
let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
//creating background
let background = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
background.backgroundColor = UIColor(red: 248/255, green: 220/255, blue: 117/255, alpha: 1)
addSubview(background)
for x in 0..<23 {
// setting values to use in the code
let rectWidth = screenWidth*0.98
let rectHeight = rectWidth*0.2408163265
let margin = Int(rectHeight*1.209039548)
//Margin settings
var yDis: Int
yDis = x*margin+(margin-Int(rectHeight))
//Building the rectangle and setting the color
let rectangle = UIView(frame: CGRect(x: 0, y: 0, width: rectWidth, height: rectHeight))
rectangle.backgroundColor = UIColor.whiteColor()
// Setting the margins
var rectFrame = CGRect(x: 0, y: 0, width: rectWidth, height: rectHeight)
rectFrame.origin.x = CGFloat(screenWidth*0.01)
rectFrame.origin.y = CGFloat(yDis)
rectangle.frame = rectFrame
// Rectangle border radius
rectangle.layer.cornerRadius = 7
addSubview(rectangle)
}
}
}
导入UIKit
类Draw2dD:UIView{
必需的初始化?(编码器aDecoder:NSCoder){
super.init(编码者:aDecoder)
//测量屏幕尺寸
让屏幕大小:CGRect=UIScreen.mainScreen().bounds
设screenWidth=screenSize.width
设screenHeight=screenSize.height
//创建背景
让background=UIView(帧:CGRect(x:0,y:0,宽度:screenWidth,高度:screenHeight))
backgroundColor=UIColor(红色:248/255,绿色:220/255,蓝色:117/255,alpha:1)
添加子视图(背景)
对于0中的x,为什么不使用UITableView
?使用UIScrollView