【发布时间】:2016-07-05 17:06:30
【问题描述】:
我已经使用以下设置设置了我的 UIImageView。我正在尝试绘制视图,但无法显示任何内容。我是 Xcode 的新手,希望我的视图能够根据屏幕大小自动更改。当我使用故事板时,我无法弄清楚如何让视图随着屏幕大小和/或旋转而改变。结果,我认为在 ViewController.swift 文件中实现这一点会更容易。当程序不工作时,我试图查看视图是否出现在屏幕上。当我将其中一个视图设为红色时,我仍然无法在屏幕上看到任何内容。我很迷茫。我愿意接受任何反馈。感谢您抽出宝贵时间阅读本文并期待获得帮助。
谢谢,
T
import UIKit
import CoreGraphics
class ViewController: UIViewController {
var ResultImageView = UIImageView ( frame: UIScreen.mainScreen().bounds)
var DrawingImageView = UIImageView ( frame: UIScreen.mainScreen().bounds)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
ResultImageView.userInteractionEnabled = true
ResultImageView.backgroundColor = UIColor.redColor()
DrawingImageView.userInteractionEnabled = true
}
【问题讨论】:
-
所以要清楚,您希望 UIImageView 调整到屏幕大小。
-
是的。我尝试了上面的代码并在某处犯了错误。当我在情节提要中这样做时,我无法弄清楚如何让它随着屏幕旋转而改变。
-
我的回答对你有用吗?
-
当我在 viewdidload 中创建变量时,我无法在整个程序中看到它。当我拉出变量行时,我收到一条错误消息,提示“'NSObject' 类型的值 - > 'ViewController' 没有成员视图。”感谢您的帮助。
-
立即尝试。我已经更新了答案
标签: xcode uiimageview viewcontroller viewdidload uiscreen