2016-10-29 4 views
0

am en utilisant Xcode 8.1, rapide 3.0contrôle 3 Segmenté

j'ai le code segmenté son travail avec 2 contrôle

lorsque je tente d'ajouter 3 sa ne fonctionne pas une idée qui ne va pas avec mon code

celui-travail avec 2 segmentée

@IBAction func showComponent(_ sender: UISegmentedControl) { 
    if sender.selectedSegmentIndex == 0 { 
     UIView.animate(withDuration: 0.0, animations: { 
     self.containerViewA.alpha = 1 
     self.containerViewB.alpha = 0 
     })  
    } else { 
     UIView.animate(withDuration: 0.0, animations: { 
     self.containerViewA.alpha = 0 
     self.containerViewB.alpha = 1 
     }) 
    } 
} 

celui-ci ne fonctionne pas avec 3 segmentée

ici essaye le nouveau code avec le contrôle segmenté 3x;

@IBAction func showComponent(_ sender: UISegmentedControl) { 
    if sender.selectedSegmentIndex == 0 { 
     UIView.animate(withDuration: 0.5, animations: { 
     self.containerViewA.alpha = 1 
     self.containerViewB.alpha = 0 
     self.containerViewC.alpha = 0 
     }) 

     UIView.animate(withDuration: 0.5, animations: { 
     self.containerViewA.alpha = 0 
     self.containerViewB.alpha = 1 
     self.containerViewC.alpha = 0 
    } else {  
     UIView.animate(withDuration: 0.5, animations: { 
     self.containerViewA.alpha = 0 
     self.containerViewB.alpha = 0 
     self.containerViewC.alpha = 1 
     }) 
    } 
} 

Répondre

0

bien je tentais avec ce code son travail maintenant :)

import UIKit 
class ViewController: UIViewController { 
    @IBOutlet weak var orange: UIView! 
    @IBOutlet weak var yellow: UIView! 
    @IBOutlet weak var red: UIView! 
    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. 
    } 
    @IBAction func showComponent(_ sender: UISegmentedControl) { 
     if sender.selectedSegmentIndex == 0 { 
       self.orange.alpha = 1 
       self.yellow.alpha = 0 
       self.red.alpha = 0 
     } 
       if sender.selectedSegmentIndex == 1 { 
       self.orange.alpha = 0 
       self.yellow.alpha = 1 
       self.red.alpha = 0 
     } 
       if sender.selectedSegmentIndex == 2 { 
       self.orange.alpha = 0 
       self.yellow.alpha = 0 
       self.red.alpha = 1 
      } 
    } 
}