2015-12-10 142 views
-2

我无法得到以下代码来编译,任何建议的人?错误 - UIImageView UIScrollView播放背景视频

import UIKit 

class ViewController: UIViewController, UIScrollViewDelegate { 

    @IBOutlet weak var avatar: UIImageView! 
    @IBOutlet weak var scrollView: UIScrollView! 
    @IBOutlet weak var contentImageView: UIImageView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     avatar.layer.cornerRadius = 5.0 
     avatar.layer.borderWidth = 4.0 
     avatar.layer.borderColor = UIColor.whiteColor().CGColor 
     avatar.clipsToBounds = true 
     scrollView.delegate = self 
     contentImageView.clipsToBounds = true 
    } 

    override func viewDidAppear(animated: Bool) { 
     let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginScreen") as! UIViewController 
     self.presentViewController(vc, animated: true, completion: nil) 
    } 

    func scrollViewDidScroll(scrollView: UIScrollView) { 
     let yOffset = self.scrollView.contentOffset.y * 0.2 
     let availableOffset = min(yOffset, 60) 
     let contentRectYOffset = availableOffset/contentImageView.frame.size.height 
     contentImageView.layer.contentsRect = CGRectMake(0.0, contentRectYOffset, 1, 1); 
    } 
} 

的错误是

“从低迷现状“的UIViewController?到'UIViewController'只展开 optionals;你的意思是使用'!'

这发生在该行

let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginScreen") as! UIViewController 
+0

有什么错误?它发生在哪里? – rmaddy

+0

错误是'从'UIViewController'下降'?到'UIViewController'只解开optionals;你的意思是使用'!' ----------这发生在行----让vc = self.storyboard?.instantiateViewControllerWithIdentifier(“LoginScreen”)as! UIViewController – Indy

+1

用所有相关细节更新您的问题,以便人们可以帮助您。 – rmaddy

回答

0

您是压低铸造的对象这已经是同一类型。您只需要删除as! UIViewController,并假设ViewController存在标识符LoginScreen,则可以在需要时强制打开vc变量。

override func viewDidAppear(animated: Bool) { 
    let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginScreen") 
    self.presentViewController(vc!, animated: true, completion: nil) 
} 
0

感谢R P,您的解决方案工作得很好。

override func viewDidAppear(animated: Bool) { 
let vc = self.storyboard?.instantiateViewControllerWithIdentifier("LoginScreen") 
self.presentViewController(vc!, animated: true, completion: nil) 

}

+1

很高兴帮助!如果解决方案有效,您可以将其标记为已回答。 –