저는 ios 프로그램으로 1분 타이머를 만들었어요.
버전
xcode Version 10.2.1
제작 과정
프로젝트를 시작합니다.
Single View APP를 사용하여 다음 화면에 ProductName 등의 필수 정보를 표시합니다.
Main.storyboard에서 UILAbel을 한가운데 위에 배치하고 아래에 세 군데의 UIButton을 start,stop,reset으로 설정합니다.
viewController.모든 swift 파일을 연결합니다.
각 부품에 대해 제한을 가하다.
이번에는 All Views in View Controller의 Add Missing Constraints에서 간단하게 진행됩니다.
view Controller는 초기 값을 실례의 생성과 변수에 대입합니다.//タイマークラスのインスタンスを生成
var timer = Timer()
//count変数に初期値0を代入
var count = 0
시작 버튼 설치//スタートボタン
@IBAction func timerStartButton(_ sender: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector:#selector(ViewController.updateTimer),
userInfo: nil, repeats: true)
}
scheduledTimer 메서드는 매개 변수에 역할을 할당합니다.
이름
설명
timeInterval
순환하면 간격, 한 번만 있으면 발동까지 초수
target
메소드 객체
selector
실행할 방법
userInfo
객체의 값
repeats
반복 실행 여부
설치 중지 버튼 //ストップボタン
@IBAction func timerStopButton(_ sendr: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
}
재설정 버튼 설치//リセットボタン
@IBAction func timerResetButton(_ sender: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
//count変数を0にする
count = 0
//timerCountLabelのtextプロパティへString型にキャストしたcount変数を代入する(表示させる)
timerCountLabel.text = String(count)
}
피양도자의 함수//移譲される側のメソッド
@objc func updateTimer() {
//countが60に達するまで1ずつ加算されていく
if count < 60 {
count += 1
//timerCountLabelのtextプロパティへString型にキャストしたcount変数を代入する(表示させる)
timerCountLabel.text = String(count)
}
완성import UIKit
class ViewController: UIViewController {
//Timerクラスのインスタンスを作成
var timer = Timer()
//countに初期値を設定
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
//ラベル
@IBOutlet weak var timerCountLabel: UILabel!
//スタートボタン
@IBAction func timerStartButton(_ sender: Any) {
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.updateTimer), userInfo: nil, repeats: true)
}
//ストップボタン
@IBAction func timerStopButton(_ sendr: Any) {
timer.invalidate()
}
//リセットボタン
@IBAction func timerResetButton(_ sender: Any) {
timer.invalidate()
count = 0
timerCountLabel.text = String(count)
}
//移譲される側の関数
@objc func updateTimer() {
if count < 60 {
count += 1
timerCountLabel.text = String(count)
}
}
}
웹 페이지 정보
Swift 4 환경에서 Timer 사용 방법 및 비헤이비어 확인
Reference
이 문제에 관하여(저는 ios 프로그램으로 1분 타이머를 만들었어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kousuke-hachiware/items/d50ccd36c205e04aefc5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
프로젝트를 시작합니다.

Single View APP를 사용하여 다음 화면에 ProductName 등의 필수 정보를 표시합니다.

Main.storyboard에서 UILAbel을 한가운데 위에 배치하고 아래에 세 군데의 UIButton을 start,stop,reset으로 설정합니다.

viewController.모든 swift 파일을 연결합니다.

각 부품에 대해 제한을 가하다.
이번에는 All Views in View Controller의 Add Missing Constraints에서 간단하게 진행됩니다.

view Controller는 초기 값을 실례의 생성과 변수에 대입합니다.
//タイマークラスのインスタンスを生成
var timer = Timer()
//count変数に初期値0を代入
var count = 0
시작 버튼 설치//スタートボタン
@IBAction func timerStartButton(_ sender: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector:#selector(ViewController.updateTimer),
userInfo: nil, repeats: true)
}
scheduledTimer 메서드는 매개 변수에 역할을 할당합니다.이름
설명
timeInterval
순환하면 간격, 한 번만 있으면 발동까지 초수
target
메소드 객체
selector
실행할 방법
userInfo
객체의 값
repeats
반복 실행 여부
설치 중지 버튼
//ストップボタン
@IBAction func timerStopButton(_ sendr: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
}
재설정 버튼 설치//リセットボタン
@IBAction func timerResetButton(_ sender: Any) {
//invalidateメソッドはオブジェクトからタイマーを削除する
timer.invalidate()
//count変数を0にする
count = 0
//timerCountLabelのtextプロパティへString型にキャストしたcount変数を代入する(表示させる)
timerCountLabel.text = String(count)
}
피양도자의 함수//移譲される側のメソッド
@objc func updateTimer() {
//countが60に達するまで1ずつ加算されていく
if count < 60 {
count += 1
//timerCountLabelのtextプロパティへString型にキャストしたcount変数を代入する(表示させる)
timerCountLabel.text = String(count)
}
완성import UIKit
class ViewController: UIViewController {
//Timerクラスのインスタンスを作成
var timer = Timer()
//countに初期値を設定
var count = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
//ラベル
@IBOutlet weak var timerCountLabel: UILabel!
//スタートボタン
@IBAction func timerStartButton(_ sender: Any) {
timer.invalidate()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(ViewController.updateTimer), userInfo: nil, repeats: true)
}
//ストップボタン
@IBAction func timerStopButton(_ sendr: Any) {
timer.invalidate()
}
//リセットボタン
@IBAction func timerResetButton(_ sender: Any) {
timer.invalidate()
count = 0
timerCountLabel.text = String(count)
}
//移譲される側の関数
@objc func updateTimer() {
if count < 60 {
count += 1
timerCountLabel.text = String(count)
}
}
}
웹 페이지 정보Swift 4 환경에서 Timer 사용 방법 및 비헤이비어 확인
Reference
이 문제에 관하여(저는 ios 프로그램으로 1분 타이머를 만들었어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kousuke-hachiware/items/d50ccd36c205e04aefc5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)