第二个视图控制器仍然对第一个ViewController swift 3作出反应

时间:2017-07-24 08:56:22

标签: ios swift swift3 uiviewcontroller segue

我正在开发一个应用程序,我必须建立自己的手势识别(Apple太精确了)

我需要使用第二个视图控制器(设置),当我在第二个视图控制器上时,它仍然会对第一个视图控制器作出反应。

如果问题很严重,那就是用这些手势来控制家里的东西(比如灯光,音乐甚至更多),所以想象一下你点击第二个视图上的按钮就可以了点亮房间,或者在第二个视图上向下滑动,音乐被切断......

我使用segue转到SecondViewController

[, https://www.facebook.com/officialstackoverflow/, https://codegolf.stackexchange.com/questions/135102/formic-functions-ant-queen-of-the-hill-contest, https://www.stackoverflowbusiness.com/advertise?utm_source=so-footer&utm_medium=referral&utm_campaign=brand-activation, https://scifi.stackexchange.com/questions/165505/what-were-mad-eye-and-neville-talking-about-after-the-unforgivable-curses-scene, https://worldbuilding.stackexchange.com/questions/86289/a-believable-place-for-your-secret-lair, https://www.stackoverflowbusiness.com/enterprise?utm_source=so-footer&utm_medium=referral&utm_campaign=brand-activation, https://stackoverflow.blog, http://stackoverflow.com/election, https://mathoverflow.net/questions/277069/what-is-homology-anyway, https://math.stackexchange.com/questions/2369011/what-is-the-best-rest-position-for-two-elevators-in-a-10-story-building, https://data.stackexchange.com, https://stackexchange.com/users/2524916/?tab=accounts, https://worldbuilding.stackexchange.com/questions/86712/what-kind-of-apocalyptic-event-can-be-predicted-years-before-it-happens, https://stackexchange.com/sites#lifearts, https://stackoverflow.com/company/work-here, https://mechanics.stackexchange.com/questions/46467/how-dangerous-is-it-to-drive-on-country-roads-with-a-potentially-failing-wheel-b, https://stackoverflow.blog/2017/07/21/trends-cloud-computing-uses-aws-uses-azure/, https://physics.stackexchange.com/questions/348279/why-does-spin-arise-in-non-relativistic-quantum-mechanics, https://serverfault.com, https://stackexchange.com/sites#science, https://dba.stackexchange.com, https://www.stackoverflowbusiness.com/?ref=topbar_help, https://meta.stackoverflow.com/questions/352065/introducing-channels-qa-for-engineering-teams, https://stackoverflow.com/company/contact, https://creativecommons.org/licenses/by-sa/3.0/, https://askubuntu.com/questions/938849/how-to-remove-text-after, https://stackexchange.com/legal, https://stackoverflow.com/users/logout, https://stackoverflow.com/company/about, https://unix.stackexchange.com/questions/381282/difference-copy-contents-folder-between-and-in-linux, https://ell.stackexchange.com/questions/137089/i-often-buy-fruits-when-i-go-to-the-supermarket-illogical, https://workplace.stackexchange.com/questions/95543/colleague-shared-pirated-material-is-it-appropriate-for-our-manager-to-make-me, https://www.stackoverflowbusiness.com/talent?utm_source=so-footer&utm_medium=referral&utm_campaign=brand-activation, https://stackoverflow.com, https://stackoverflow.com/help, https://stackexchange.com, https://stackexchange.com/questions?tab=hot, https://chemistry.stackexchange.com/questions/80287/mo-theory-why-do-hydrogen-and-lithium-bond-but-hydrogen-and-helium-dont, https://linkedin.com/company/stack-overflow, https://meta.stackoverflow.com, https://api.stackexchange.com, https://www.facebook.com/sharer.php?u=https%3a%2f%2fstackoverflow.com%2fq%2f45274717%2f2194470%3fsfb%3d2, https://tex.stackexchange.com/questions/382967/using-cmbright-only-as-a-math-font, https://movies.stackexchange.com/questions/77763/was-ras-al-ghul-nearly-immortal-in-the-dark-knight-trilogy, https://stackoverflow.blog?blb=1, https://stackoverflow.com/company/press, https://stackoverflow.com/jobs/directory/developer-jobs, https://worldbuilding.stackexchange.com/questions/86914/what-is-a-logical-explanation-for-why-a-race-of-stone-humanoids-wouldnt-become, https://ell.stackexchange.com/questions/137104/what-does-it-mean-by-a-cheery-lot, https://stackexchange.com/sites#culturerecreation, https://stackoverflow.com/questions/45273948/what-happens-when-setstate-function-is-called, https://twitter.com/stackoverflow, https://stackexchange.com/sites#technology, https://politics.stackexchange.com/questions/22003/is-identity-politics-vs-freedom-of-speech-a-valid-dichotomy, https://stackoverflow.blog/2009/06/25/attribution-required/, https://stackoverflow.com/questions/45268467/is-131-well-defined-in-c-when-sizeofint-4, https://workplace.stackexchange.com/questions/95638/how-can-i-increase-focus-when-doing-something-boring, https://chat.stackoverflow.com, https://travel.stackexchange.com/questions/98642/which-safety-features-of-the-german-autobahn-make-it-possible-to-have-no-speed-l, https://meta.stackoverflow.com/questions/352386/2017-moderator-election-qa-questionnaire, https://academia.stackexchange.com/questions/93408/what-is-the-point-of-being-the-head-of-the-department, https://www.stackoverflowbusiness.com/?utm_source=so-footer&utm_medium=referral&utm_campaign=brand-activation, mailto:?subject=Stack%20Overflow%20Question&body=Parse%20HTML%20for%20Links%0Ahttps%3a%2f%2fstackoverflow.com%2fq%2f45274717%2f2194470%3fsem%3d2, https://stackexchange.com/legal/privacy-policy, https://stackexchange.com/sites, https://www.stackoverflowbusiness.com/insights?utm_source=so-footer&utm_medium=referral&utm_campaign=brand-activation, https://twitter.com/share?url=https%3a%2f%2fstackoverflow.com%2fq%2f45274717%2f2194470%3fstw%3d2, https://plus.google.com/share?url=https%3a%2f%2fstackoverflow.com%2fq%2f45274717%2f2194470%3fsgp%3d2, https://mathoverflow.net/questions/277113/polynomials-leaving-invariant-the-gaussian-integers]

我为第二个视图控制器创建了另一个swift文件,现在,没有任何内容。

你知道发生了什么以及如何解决这个问题吗?

谢谢!

编辑:根据要求,这里有更多代码:

self.performSegue(withIdentifier: "SecondViewController", sender:self)

在第二个视图控制器中:

import UIKit

class ViewController: UIViewController {
//Variables definition

override func viewDidLoad() {
    super.viewDidLoad()
    ascending = false
    UIScreen.main.wantsSoftwareDimming = true
    UIScreen.main.brightness = (0.0)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    self.timer.invalidate()
    isPinched = false
    super.touchesBegan(touches, with: event)
    startTime = getCurrentMillis()

    for touch in touches{
        let point = touch.location(in: self.view)
        for (index,finger)  in fingers.enumerated() {
            if finger == nil {
                fingers[index] = String(format: "%p", touch)

                if (finger1.isEmpty){
                    finger1 = [point.x, point.y]
                } 
                //And so on until finger10
                break
            }
        }
    }

    //If the gesture is long enough, I have a special recognition (longPress)

    timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(increaseValue), userInfo: nil, repeats: true)
    if ascending {
        ascending = false
    }
    else {
        ascending = true
    }
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesMoved(touches, with: event)

    for touch in touches {
        let point = touch.location(in: self.view)
        for (index,finger) in fingers.enumerated() {
            if let finger = finger, finger == String(format: "%p", touch) {
                switch (index){
                case 0 :
                    finger1 += [point.x, point.y]
                //And so on until case 9 / finger10
                default :
                    break
                }
            }
        }
    }
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesEnded(touches, with: event)
    endTime = getCurrentMillis()

    for touch in touches {
        for (index,finger) in fingers.enumerated() {
            if let finger = finger, finger == String(format: "%p", touch) {
                fingers[index] = nil
                break
            }
        }
    }

    direction[0] = ""
    direction[1] = ""
    direction[2] = ""
    direction[3] = ""
    direction[4] = ""

    if finger1.count != 0 {
        direction[0] = GestureRecognizer(coordinates: finger1, index: 0)
    }
    if finger2.count != 0 {
        direction[1] = GestureRecognizer(coordinates: finger2, index: 1)
    }
    if finger3.count != 0 {
        direction[2] = GestureRecognizer(coordinates: finger3, index: 2)
    }
    if finger4.count != 0 {
        direction[3] = GestureRecognizer(coordinates: finger4, index: 3)
    }
    if finger5.count != 0 {
        direction[4] = GestureRecognizer(coordinates: finger5, index: 4)
    }


    if Int64(endTime - startTime) < 600 {
//My gesture recognition 
    }

    DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
        self.directionLabel.text = self.labelUpdate
        self.finger1 = []
        self.finger2 = []
        self.finger3 = []
        self.finger4 = []
        self.finger5 = []
        self.finger6 = []
        self.finger7 = []
        self.finger8 = []
        self.finger9 = []
        self.finger10 = []
    }
}

//One of the function I call
func swipeLeftTwo(){
    request(urlAdress: "Url Adress")
}

func swipeRightFour(){
        self.performSegue(withIdentifier: "SecondViewController", sender:self)
}
}

0 个答案:

没有答案