2017-03-26 9 views
0

私はnavigationControllerに2 UIViewControllersを持っています。私は1秒delaysecondViewController disappearsから"back button"ビューを押し遅延スウィフトで表示が消える

P.S.私はsecondViewControllerのビューを初期化するためにiCarouselポッドを使用します。

を見るスクリーンショット:

Iは相互に "戻る" ボタンを押してください:

enter image description here

FirstController 1秒後(第2のコントローラからビューが消え)

enter image description here

更新: 第二のViewController

class AppsController : UIViewController, iCarouselDataSource, iCarouselDelegate { 
let xmlHelper = XmlHelper() 
var apps = Apps(data:[App]()) 
var selectUrl = "" 
var selectTitle = "" 
var scrollIndex = 0 

@IBOutlet var carousel: iCarousel! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.carousel.delegate = self 
    self.carousel.isPagingEnabled = true 
    DispatchQueue.main.async { 
     self.initApps() 
    } 
} 

func numberOfItems(in carousel: iCarousel) -> Int { 
    return apps.data.count 
} 

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView { 
    let appView: AppView = Bundle.main.loadNibNamed("appView", 
                owner: nil, 
                options: nil)?.first as! AppView! 
    appView.titleLabel?.text = apps.data[index].title 
    appView.descLabel?.text = apps.data[index].desc 
    appView.frame = CGRect(x:0, y:0, width:self.view.frame.width-30, height:carousel.frame.height-60) 
    appView.backgroundColor = UIColor.white 

    var shadowLayer: CAShapeLayer! 
    shadowLayer = CAShapeLayer() 
    shadowLayer.path = UIBezierPath(roundedRect: appView.bounds, cornerRadius: 0).cgPath 
    shadowLayer.fillColor = UIColor.white.cgColor 

    shadowLayer.shadowColor = UIColor.lightGray.cgColor 
    shadowLayer.shadowPath = shadowLayer.path 
    shadowLayer.shadowOffset = CGSize(width: 0.0, height: 0.0) 
    shadowLayer.shadowOpacity = 0.8 
    shadowLayer.shadowRadius = 2 

    appView.layer.insertSublayer(shadowLayer, at: 0) 

    appView.storeButton.addTarget(self, action: #selector(didTapApp), for: UIControlEvents.touchUpInside) 

    DispatchQueue.main.async { 
     appView.iconView?.sd_setImage(with: URL(string:self.apps.data[index].icon 
      ), completed: { (image, error, cache, url) in 
       if error == nil { 
        appView.iconView.image = appView.iconView.image?.cropToBounds(image: image!, width: 30, height: 30) 
       } 
     }) 
    } 
    return appView 
} 


func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat { 
    if (option == .spacing) { 
     return value * 1.1 
    } 
    return value 
} 


func didTapApp() { 
    if self.apps.data.count != 0 { 
     UIApplication.shared.open(URL(string: "itms://itunes.apple.com/app/id" + self.apps.data[carousel.currentItemIndex].link)!, options: [:], completionHandler: nil) 
    } 
} 

func initApps() { 
    xmlHelper.getAnoutherApps { (apps) in 
     if apps != nil{ 
      self.apps = apps! 
      self.carousel.reloadData() 
     } 
    } 
} 


override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    let backItem = UIBarButtonItem() 
    backItem.title = constants.back 
    navigationItem.backBarButtonItem = backItem 
    if segue.identifier == "toWeb" { 
     let vc = segue.destination as! WebController 
     vc.fileUrl = nil 
     vc.url = self.selectUrl 
     vc.title = self.selectTitle 
     self.tabBarController?.tabBar.isHidden = true 
    } 
} 

APPVIEW(遅延で消失)

class AppView : UIView { 
@IBOutlet var titleLabel : UILabel! 
@IBOutlet var descLabel : UILabel! 
@IBOutlet var iconView : UIImageView! 
@IBOutlet var storeButton : UIButton! 
} 

第1コントローラ

class SettingsController : UITableViewController, MFMailComposeViewControllerDelegate { 


var selectUrl : URL? 
var selectTitle = "" 
var selectStringUrl = "" 

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.initUI() 
} 

override func numberOfSections(in tableView: UITableView) -> Int { 
    return 4 
} 

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    switch section { 
    case 0: 
     return 2 
    case 1: 
     return 1 
    case 2: 
     return 1 
    case 3: 
     return 3 
    default: 
     return 0 
    } 
} 

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    switch section { 
    case 0: 
     return constants.info 
    case 1: 
     return constants.settings 
    case 2: 
     return constants.connect 
    case 3: 
     return constants.community 
    default: 
     return "" 
    } 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "settingsTitleCell")! 
    let itemSize = CGSize(width:30, height:30); 
    UIGraphicsBeginImageContextWithOptions(itemSize, false, UIScreen.main.scale); 
    let imageRect = CGRect(x:0.0, y:0.0, width:itemSize.width, height:itemSize.height); 
    cell.imageView?.image!.draw(in: imageRect) 
    cell.imageView?.image! = UIGraphicsGetImageFromCurrentImageContext()!; 
    UIGraphicsEndImageContext(); 
    switch indexPath.section { 
    case 0: 
     let cell = tableView.dequeueReusableCell(withIdentifier: "settingsTitleCell")! 
     cell.textLabel?.text = constants.infoTitles[indexPath.row] 
     cell.detailTextLabel?.text = constants.infoDetail[indexPath.row] 
     cell.imageView?.image = cell.imageView?.image?.cropToBounds(image: constants.infoImages[indexPath.row], width: 30, height: 30) 
     return cell 
    case 1: 
      let cell = tableView.dequeueReusableCell(withIdentifier: "fontCell") as! FontCell 
      return cell 
    case 2: 
     let cell = tableView.dequeueReusableCell(withIdentifier: "settingsTitleCell")! 
     cell.textLabel?.text = constants.connectTitles[indexPath.row] 
     cell.imageView?.image = cell.imageView?.image?.cropToBounds(image: constants.connectImages[indexPath.row], width: 30, height: 30) 
     cell.detailTextLabel?.text = "" 
     return cell 
    case 3: 
     let cell = tableView.dequeueReusableCell(withIdentifier: "settingsTitleCell")! 
     cell.textLabel?.text = constants.communityTitles[indexPath.row] 
     cell.detailTextLabel?.text = constants.communityDetail[indexPath.row] 
     cell.imageView?.image = cell.imageView?.image?.cropToBounds(image: constants.communityImages[indexPath.row], width: 30, height: 30) 
     return cell 
    default: 
     return cell 
    } 
} 

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
    if indexPath.section == 1 { 
     return 80 
    } else { 
     return 45 
    } 
} 

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
    switch indexPath.section { 
    case 0: 
     if indexPath.row == 0 { 
      self.initWebView(url: Bundle.main.url(forResource: "caution", withExtension: "html"), stringUrl: nil, titlePage: constants.infoTitles[indexPath.row]) 
     } else { 
      self.selectTitle = constants.infoTitles[indexPath.row] 
      self.performSegue(withIdentifier: "toApps", sender: self) 
     } 
    case 2: 
     self.sendMessage() 
     break; 
    case 3: 
     switch indexPath.row { 
     case 0: 
      self.initWebView(url: Bundle.main.url(forResource: "about", withExtension: "html"), stringUrl: nil, titlePage: constants.communityTitles[indexPath.row]) 
      break; 
     case 1: 
      self.initWebView(url: nil, stringUrl: "https://vk.com/electronicengineer", titlePage: constants.communityTitles[indexPath.row]) 
     case 2: 
      self.initWebView(url: nil, stringUrl: "https://fb.com", titlePage: constants.communityTitles[indexPath.row]) 
      break; 
     default: 
      break; 
     } 
    default: 
     break; 
    } 
} 

func initUI() { 
    self.title = constants.settings 
    self.tableView.tableFooterView = UIView() 
} 

func initWebView(url:URL?, stringUrl:String?, titlePage:String) { 
    if stringUrl != nil { 
     self.selectStringUrl = stringUrl! 
     self.selectUrl = nil 
    } else { 
     self.selectUrl = url! 
    } 
    self.selectTitle = titlePage 
    self.performSegue(withIdentifier: "toWeb", sender: self) 
} 

func sendMessage() { 
    let mailComposeViewController = configuredMailComposeViewController() 
    if MFMailComposeViewController.canSendMail() { 
     self.present(mailComposeViewController, animated: true, completion: nil) 
    } 
} 

func configuredMailComposeViewController() -> MFMailComposeViewController { 
    let mailComposerVC = MFMailComposeViewController() 
    mailComposerVC.mailComposeDelegate = self 
    mailComposerVC.setToRecipients(["[email protected]"]) 
    mailComposerVC.setSubject("Электроник на Android") 
    mailComposerVC.setMessageBody("", isHTML: false) 
    return mailComposerVC 
} 


func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { 
    controller.dismiss(animated: true, completion: nil) 
} 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    let backItem = UIBarButtonItem() 
    backItem.title = constants.back 
    navigationItem.backBarButtonItem = backItem 
    if segue.identifier == "toWeb" { 
     let vc = segue.destination as! WebController 
     vc.fileUrl = self.selectUrl 
     vc.url = self.selectStringUrl 
     vc.title = self.selectTitle 
     self.tabBarController?.tabBar.isHidden = true 
    } 
    if segue.identifier == "toApps" { 
     let vc = segue.destination as! AppsController 
     vc.title = self.selectTitle 
     self.tabBarController?.tabBar.isHidden = true 
    } 
} 
} 
+0

私たちにコードを教えてください。誰もその情報だけであなたを助けることはできません。 –

+0

@ParthoBiswas、更新コードをご覧ください –

答えて

2

問題解決:

override func viewWillDisappear(_ animated: Bool) { 
    super.viewWillDisappear(true) 
    self.carousel.isHidden = true 
} 

override func viewWillAppear(_ animated: Bool) { 
    super.viewWillAppear(true) 
    self.carousel.isHidden = false 
} 
関連する問題