【问题标题】:control 3 Segmented控制 3 分段
【发布时间】:2016-10-29 05:36:42
【问题描述】:

我正在使用 Xcode 8.1 , swift 3.0

我有代码用 2 个控件分段它的工作

当我尝试添加 3 时,它不知道我的代码有什么问题

这一项与 2 Segmented 一起工作

@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
      })
   } 
} 

这个不能使用 3 Segmented

这里正在尝试使用 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
      })
   } 
} 

【问题讨论】:

    标签: ios controls swift3 segmentedcontrol


    【解决方案1】:

    我正在尝试使用这段代码,现在它的工作:)

    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
              }
         }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      相关资源
      最近更新 更多