然后我有一个被实例化并通过方法显示的UIViewController类,问题在于self.present视图的结束没有完全显示,但只有一部分显示,大约5-6秒后,视图的其余部分也会显示!如何让视图完全出现在self.present的末尾?
SWIFT代码:
///First Method (It's call nextviewcontroller
var ret: Bool = false
let c = c(c: self.c!)
c.crea(n: self.txtn.text!, completion: { result in
ret = result
})
if(ret == true)
{
let viewnext = NextViewController(c: c)
self.present(viewnext, animated: true, completion: { () in print("Done") })
}
//NextViewController.swift
class NextViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
//Oggetti Privati
private var TextViewDesc: UITextView = UITextView()
private var pickerviewStato: UIPickerView = UIPickerView()
private var labelnameINFO: UILabel = UILabel()
private var labelClientINFO: UILabel = UILabel()
private var labelfilINFO: UILabel = UILabel()
private var labelClient: UILabel = UILabel()
private var labelfil: UILabel = UILabel()
private var buttonris: UIButton = UIButton(type: .custom)
private var buttonKilometri = UIButton(type: .custom)
private var buttonfield = UIButton(type: .custom)
private var buttonprint = UIButton(type: .custom)
private var buttonReturn = UIButton()
private let statoCantiere = ["InCorso", "Chiuso", "Lavoro terminato inserire bolle"]
private var immagineStatoCantiere: UIImageView = UIImageView()
private let DistLtoR: CGFloat = 130
private let DistRtoL: CGFloat = 50
//Oggetti Pubblici
var c: c
init(c: c) {
c = c
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
hideKeyboardWhenTappedAround()
self.view.backgroundColor = UIColor.white
initView()
}
func initView() {
labelnameINFO = UILabel(frame: CGRect(x: 20, y: 60, width: 120, height: 21))
labelnameINFO.text = "Cantiere:"
labelnameINFO.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
self.view.addSubview(labelnameINFO)
let labelname = UILabel(frame: CGRect(x: 100, y: 60, width: 200, height: 21))
labelname.text = CantiereInterno.Getname()
self.view.addSubview(labelname)
labelClientINFO = UILabel(frame: CGRect(x: 20, y: 100, width: 130, height: 21))
labelClientINFO.text = "Ragione Sociale:"
labelClientINFO.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
self.view.addSubview(labelClientINFO)
labelClient = UILabel(frame: CGRect(x: 180, y: 100, width: 180, height: 21))
labelClient.text = c.GetRagioneSociale()
self.view.addSubview(labelClient)
//Configurazioe label fil
labelfilINFO = UILabel(frame: CGRect(x: 20, y: 140, width: 130, height: 21))
labelfilINFO.text = "fil:"
labelfilINFO.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
self.view.addSubview(labelfilINFO)
labelfil = UILabel(frame: CGRect(x: 100, y: 140, width: 180, height: 21))
labelfil.text = c.Getfil()
self.view.addSubview(labelfil)
let labelStato = UILabel(frame: CGRect(x: 20, y: 190, width: 130, height: 21))
labelStato.text = "Stato:"
labelStato.font = UIFont(name: "HelveticaNeue-Bold", size: 16.0)
self.view.addSubview(labelStato)
self.pickerviewStato = UIPickerView(frame: CGRect(x: 90, y: 180, width: 160, height: 50))
self.pickerviewStato.delegate = self as UIPickerViewDelegate
self.pickerviewStato.dataSource = self as UIPickerViewDataSource
self.pickerviewStato.backgroundColor = UIColor.gray
self.view.addSubview(pickerviewStato)
immagineStatoCantiere = UIImageView(frame: CGRect(x: (self.view.frame.width / 2) + 50, y: 180, width: 50, height: 50));
immagineStatoCantiere.image = UIImage(named: "InCorso.png")
immagineStatoCantiere.backgroundColor = UIColor.gray
self.view.addSubview(immagineStatoCantiere)
self.TextViewDesc = UITextView(frame: CGRect(x: 0, y: 250, width: self.view.frame.width, height: 80))
self.automaticallyAdjustsScrollViewInsets = false
TextViewDesc.font = UIFont(name: "HelveticaNeue-Bold", size: 18.0)
TextViewDesc.textAlignment = NSTextAlignment.justified
TextViewDesc.textColor = UIColor.blue
TextViewDesc.isEditable = true
TextViewDesc.backgroundColor = UIColor.lightGray
TextViewDesc.text = c.GetDescrizioneEstesa()
self.view.addSubview(TextViewDesc)
buttonris.frame = CGRect(x: (self.view.frame.width / 2) - DistLtoR, y: 380, width: 100, height: 100)
buttonris.layer.cornerRadius = 0.5 * buttonris.bounds.size.width
buttonris.clipsToBounds = true
buttonris.setImage(UIImage(named: "risorse_umane.png"), for: .normal)
buttonris.backgroundColor = UIColor.lightGray
buttonris.addTarget(self, action: #selector(risbuttonAction), for: .touchUpInside)
self.view.addSubview(buttonris)
buttonKilometri.frame = CGRect(x: (self.view.frame.width / 2) + DistRtoL, y: 380, width: 100, height: 100)
buttonKilometri.layer.cornerRadius = 0.5 * buttonKilometri.bounds.size.width
buttonKilometri.clipsToBounds = true
buttonKilometri.setImage(UIImage(named: "kilometri.png"), for: .normal)
buttonKilometri.backgroundColor = UIColor.lightGray
buttonKilometri.addTarget(self, action: #selector(KilometributtonAction), for: .touchUpInside)
self.view.addSubview(buttonKilometri)
buttonfield.frame = CGRect(x: (self.view.frame.width / 2) - DistLtoR, y: 500, width: 100, height: 100)
buttonfield.layer.cornerRadius = 0.5 * buttonfield.bounds.size.width
buttonfield.clipsToBounds = true
buttonfield.setImage(UIImage(named: "field.png"), for: .normal)
buttonfield.backgroundColor = UIColor.lightGray
buttonfield.addTarget(self, action: #selector(fieldbuttonAction), for: .touchUpInside)
self.view.addSubview(buttonfield)
buttonprint.frame = CGRect(x: (self.view.frame.width / 2) + DistRtoL, y: 500, width: 100, height: 100)
buttonprint.layer.cornerRadius = 0.5 * buttonfield.bounds.size.width
buttonprint.clipsToBounds = true
buttonprint.setImage(UIImage(named: "print.png"), for: .normal)
buttonprint.backgroundColor = UIColor.lightGray
buttonprint.addTarget(self, action: #selector(RapportinobuttonAction), for: .touchUpInside)
self.view.addSubview(buttonprint)
buttonprint.isHidden = false
buttonReturn.frame = CGRect(x: (self.view.frame.width / 2), y: 600, width: 80, height: 80)
buttonReturn.backgroundColor = UIColor.white
buttonReturn.setImage(UIImage(named: "return.png"), for: .normal)
buttonReturn.setTitle("Go Home", for: .normal)
buttonReturn.addTarget(self, action: #selector(ReturnToHomebuttonAction), for: .touchUpInside)
self.view.addSubview(buttonReturn)
}
在viewwillappear中调用initView:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if labelnameINFO == nil{
self.initView()
}
}