我刚开始在swift中制作IOS应用程序。在所有教程中,人们将一个Image视图拖到视图控制器,并自动调用自己的UIImageView并填充整个屏幕。图片视图VS UIImage View Xcode placement
当我拖动图像视图时,它将自己命名为图像视图,并且永远不会填满整个屏幕。有谁知道如何让我的xcode像他们一样行事?
教程问题:https://www.youtube.com/watch?v=4eP_xW-Zz34
MORE INFO(非必要):
然后我跟着教程(七月2015ish制造),当我做到这一点的代码永远不会编译只是他们的方式它(减去UIImage vs图片)。总有一些事情要做。
是不是只是切换到一个新版本的swift/xcode,使所有这些教程过时或有一些代码设置,我需要改变,使代码工作。
更具体的代码差异和新兴错误
其代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var photoImageView: UIImageView!
// Create a place to render the filtered image
let context = CIContext(options: nil)
@IBAction func applyFilter(sender: AnyObject) {
// Create an image to filter
let inputImage = CIImage(image: photoImageView.image)
// Create a random color to pass to a filter
let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314))/100)]
// Apply a filter to the image
let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)
// Render the filtered image
let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())
// Reflect the change back in the interface
photoImageView.image = UIImage(CGImage: renderedImage)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
错误,我从该代码得到:
let inputImage = CIImage(image: photoImageView.image)
给出了错误:Value of optional type 'UIImage?' not unwrapped; did you mean to use '!' or '?'?
原因我包含这段代码,错误是因为我认为它与xcode与Image Views的行为差异有关,并可能有助于查明这些问题的原因。
的Xcode做的Xcode 7,斯威夫特2 *:
注建议修复,但该代码错误真的是一个添加到最初问题上的第二点,是我的Xcode不同,如果是的话,我可以不这样做。 – Rorschach
确定您的xCode与指令的版本不同。你知道,Swift编译器仍然在不断发展,这使得一些代码在旧编译器上是好的,但是在新编译器上却没有。 –