加载uiview时出现黑屏
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了加载uiview时出现黑屏相关的知识,希望对你有一定的参考价值。
我遇到的问题是当我加载这个UIViewController.removeSpinner(spinner:self.view)
它给了我一个空白的黑色视图,我不知道如何从按钮功能访问sv变量:
让sv = UIViewController.displaySpinner(onView:self.view)
即时通讯使用此扩展来加载微调器并删除qazxsw poi
我真正想做的事情:
1-获取语音留言的网址。
2-运行微调器以加载播放器。
3-玩。
4-如果观察者发现它已经结束,则删除微调器。
这是我的代码:
http://brainwashinc.com/2017/07/21/loading-activity-indicator-ios-swift/
答案
你应该做更像的事情
@IBAction func vnClick(_ sender: UIButton) {
let vnInfo = itemss[sender.tag]
print(vnInfo.vnUrl)
let sv = UIViewController.displaySpinner(onView: self.view)
if let url = NSURL(string: vnInfo.vnUrl) {
player = AVPlayer(url: url as URL)
player.play()
//check if ended playing to remove spinner
NotificationCenter.default.addObserver(self, selector:#selector(playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
}
}
@objc func playerDidFinishPlaying(note: NSNotification) {
UIViewController.removeSpinner(spinner: self.view)
}
另一答案
你的错误是你在这里传递self.view,这将删除视图
playerDidFinishPlaying()中的UIViewController.removeSpinner(spinner:self.view)
你需要这样做,把spinnerview对象放在按钮点击之外,
private var sv : UIView?
@IBAction func vnClick(_ sender: UIButton) {
let vnInfo = itemss[sender.tag]
print(vnInfo.vnUrl)
sv = UIViewController.displaySpinner(onView: self.view)
if let url = NSURL(string: vnInfo.vnUrl) {
player = AVPlayer(url: url as URL)
player.play()
//check if ended playing to remove spinner
NotificationCenter.default.addObserver(self, selector:#selector(playerDidFinishPlaying(note:)),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)
}
}
@objc func playerDidFinishPlaying(note: NSNotification) {
if let sv = sv {
UIViewController.removeSpinner(spinner: sv)
}
}
分配,
var spinnerView: UIView!
在删除时,传递spinnerview而不是self.view
spinnerView = UIViewController.displaySpinner(onView: self.view)
代码就像,
UIViewController.removeSpinner(spinner: self.spinnerView)
以上是关于加载uiview时出现黑屏的主要内容,如果未能解决你的问题,请参考以下文章
iOS swiftDelegate 文件在添加代码时出现黑屏,请指导
快速切换到 UITableViewController 时出现黑屏