ios 快速向后滑动

6jjcrrmo  于 2022-12-20  发布在  iOS
关注(0)|答案(1)|浏览(114)
import UIKit

let alert = UIAlertController(title: "Warning",
               message: "Your number is too big.",
               preferredStyle: .alert)

  
  class ViewController: UIViewController {
          
    // Verbindungen zu Storyboard
 
    @IBAction func rechnerEntry(_ sender: Any) {
    }
     
    @IBOutlet weak var resultLabel: UILabel!
     
    @IBOutlet weak var buttons: UIButton!
     
    @IBAction func clear(_ sender: Any) {
       
      calculatorLabel.text = ""
      number = 0
    }
     
    override func viewDidLoad() {
      super.viewDidLoad()
     
      buttons.backgroundColor = UIColor.gray
    }
     
    // Aufführung happyFuncs
     
    func happyFunc(number: Int) -> Int {
       
      var myNum = number
      var sum = 0
      while myNum > 0 {
        let x = myNum % 10
        sum += (x * x)
        myNum /= 10
      }
      return sum
    }
     
    // happyCheckerFunc
     
    func happyChecker(_ x: Int) -> Bool {
      var alreadychecked: Set<Int> = Set()
      var result = happyFunc(number: x)
     
      while !alreadychecked.contains(result) {
         
        if result == 1 {
          resultLabel.text = "your number is a happy number"
          return true
        }
         
        alreadychecked.insert(result)
        result = happyFunc(number: result)
      }
      resultLabel.text = "your number is a unhappy number"
      return false
    }
     
    // Eingabe Werte
     
    var number = 0
    var x = 0
     
    @IBOutlet weak var calculatorLabel: UILabel!
     
    var isTypingNumber = false
     
    // Nummer getippt
     
    @IBAction func numberTapped(_ sender: UIButton) {
       
      let number = sender.currentTitle ?? (sender.titleLabel?.text ?? "0")
       
      if isTypingNumber {
        calculatorLabel.text = calculatorLabel.text! + number
      } else {
        calculatorLabel.text = number
        isTypingNumber = true
      }
       
    }
   
    // Überprüfung happy?
     
    @IBAction func happycheck(_ sender: UIButton) {
       
      number = Int(calculatorLabel.text!)!
       
      x = number
       
      if x > 9999999999999999 {
        alert.addAction(UIAlertAction(title: "OK",
                       style: .default,
                       handler: { _ in
           print("OK tap")
        }))
        present(alert, animated: true, completion: nil)
         
      }
      func happyFunc(number: Int) -> Int {
         
        var myNum = number
        var sum = 0
        while myNum > 0 {
          let x = myNum % 10
          sum += (x * x)
          myNum /= 10
        }
        return sum
      }
      
      func happyChecker(_ x: Int) -> Bool {
        var alreadychecked: Set<Int> = Set()
        var result = happyFunc(number: x)
         
        while !alreadychecked.contains(result) {
           
          if result == 1 {
            resultLabel.text = "your number is a happy number"
            return true
          }
           
          alreadychecked.insert(result)
          result = happyFunc(number: result)
        }
        resultLabel.text = "your number is a unhappy number"
        return false
      }
       
      happyChecker(x)
    }
  
  }

storyboard
嘿,我想问你如何在Swift中实现向后滑动手势。所以我希望用户从主视图控制器开始,然后点击“快乐数字Rechner”按钮,然后出现计算器视图控制器。就像iOS设置应用程序中的过渡一样。如果你向左滑动,主视图应该会再次出现。谢谢!

nfg76nw0

nfg76nw01#

你将需要NavigationController, and ViewController你可以找到并添加这个像当你添加一个按钮。之后点击你的按钮,按住选项按钮你的键盘,并拉在一起的第一和第二视图控制器,现在添加你一个导航控制器(你会看到2屏幕,只是删除一个tableview控制器屏幕),不要忘记把一个新的方式你的箭头。(导航控制器第一)

相关问题