iOS開發中突如其來的 override can only be specified on class member錯誤排除







 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
//  ViewController.swift
//  iListenVer1
//
//  Created by Abraham on 2017/6/4.
//  Copyright © 2017年 Abraham. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var titleLabel: UITextView!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var bear: UIImageView!
    var indicator = UIActivityIndicatorView()
    @IBOutlet weak var loadingPosView: UIView!
    
    //當此頁面計數到3之後就跳下一頁
    var sum:Int = 0
    var n:Int = 3
    
    override func viewDidAppear(_ animated: Bool) {
        
        UIView.animate(withDuration: 1, delay: 0, options: .transitionFlipFromBottom, animations: {
            self.titleLabel.frame.origin.x = self.titleLabel.frame.origin.x
            self.titleLabel.frame.origin.y = self.titleLabel.frame.origin.y + 20
            self.titleLabel.alpha = 0
            self.titleLabel.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
            })
        { finish -> Void in
            UIView.animate(withDuration: 2, delay: 0, options: .repeat, animations: {
                self.bear.frame.origin.x = self.bear.frame.origin.x + 50
                self.bear.alpha = 0
                self.bear.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
            }) { finish->Void in
                print("animation ended!!")
        }
        
        
        UIView.animate(withDuration: 2, delay: 0, options: .repeat, animations: {
            self.bear.frame.origin.x = self.bear.frame.origin.x + 50
            self.bear.alpha = 0
            self.bear.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
        }) { finish->Void in
                print("animation ended!!")
        }
        
        /*
        UIView.animate(withDuration: 2.0 , animations:{
            self.bear.frame.origin.x = self.bear.frame.origin.x + 50
            self.bear.alpha = 0
            self.bear.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
        })
        */
    }
    
    
    func goToSecondView(){
        self.present(LoginView(),animated:true , completion:nil)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        indicator.center = self.loadingPosView.center
        indicator.activityIndicatorViewStyle = .gray
        indicator.transform = CGAffineTransform(scaleX: 3, y: 3)
        self.view.addSubview(indicator)
        indicator.startAnimating()
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}




嘗試過重新開啟專案執行
並無法解決

後來修正並查證發現
是少了括號的問題!!!!


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
//  ViewController.swift
//  iListenVer1
//
//  Created by Abraham on 2017/6/4.
//  Copyright © 2017年 Abraham. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var titleLabel: UITextView!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var bear: UIImageView!
    var indicator = UIActivityIndicatorView()
    @IBOutlet weak var loadingPosView: UIView!
    
    func goToSecondView(){
        self.present(LoginView(),animated:true , completion:nil)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        UIView.animate(withDuration: 5, delay: 0, options: .transitionFlipFromBottom, animations: {
            self.titleLabel.frame.origin.x = self.titleLabel.frame.origin.x
            self.titleLabel.frame.origin.y = self.titleLabel.frame.origin.y + 20
            self.titleLabel.alpha = 0
            self.titleLabel.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
        })
        { finish -> Void in
            UIView.animate(withDuration: 2, delay: 0, options: .repeat, animations: {
                self.bear.frame.origin.x = self.bear.frame.origin.x + 50
                self.bear.alpha = 0
                self.bear.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
            }) { finish->Void in
                print("animation ended!!")
            }
        }
        
        UIView.animate(withDuration: 2, delay: 0, options: .repeat, animations: {
            self.bear.frame.origin.x = self.bear.frame.origin.x + 50
            self.bear.alpha = 0
            self.bear.transform = CGAffineTransform(scaleX: 2.0, y: 2.0)
        }) { finish->Void in
            print("animation ended!!")
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        indicator.center = self.loadingPosView.center
        indicator.activityIndicatorViewStyle = .gray
        indicator.transform = CGAffineTransform(scaleX: 3, y: 3)
        self.view.addSubview(indicator)
        indicator.startAnimating()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}







Reference link:

https://stackoverflow.com/questions/26828504/swift-override-can-only-be-specified-on-class-members


https://forums.developer.apple.com/thread/54262






留言

這個網誌中的熱門文章

何謂淨重(Net Weight)、皮重(Tare Weight)與毛重(Gross Weight)

Architecture(架構) 和 Framework(框架) 有何不同?_軟體設計前的事前規劃的藍圖概念

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題