滑动识别器只能识别一个方向

时间:2019-08-23 23:25:21

标签: swift

swipegesturerecognizer仅识别正确的方向。 左,上或下无法识别,甚至不调用选择器

am使用Swift 5 Xcode 10.3

chromedriver_path = r"C:\Users\path\to\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"

topics_xpath = "//div[@class='divTopicsSection1']//span//label[text()='All Topics']"
states_xpath = "//div[@class='divStatesSection1']//span//label[text()='All States']"
dBase_xpath = "//h4[text()='Searchable Database']"
browser.get(url)
WebDriverWait(browser, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))
elem = browser.find_element_by_xpath(dBase_xpath)
browser.execute_script("arguments[0].scrollIntoView(true);", elem)

browser.find_element_by_xpath(topics_xpath).click()
browser.find_element_by_xpath(states_xpath).click()

上面的代码在向右滑动时显示“向右滑动”

向左滑动一无所有

2 个答案:

答案 0 :(得分:0)

非常感谢

通过添加两个滑动手势识别器来工作 我分别定义方向,然后将其附加到视图 每个都有单独的选择器处理程序

func setupUserInteraction(){
    self.view.isUserInteractionEnabled = true
    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeRight))
    swipeRight.direction = .right
    view.addGestureRecognizer(swipeRight)

    let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipeLeft))
    swipeLeft.direction = .left
    view.addGestureRecognizer(swipeLeft)
}

@objc func handleSwipeRight(){
    print("Swipe Right")
}

@objc func handleSwipeLeft(){
    print("Swipe Left")
}

答案 1 :(得分:-1)

添加到@matt上时,滑动识别器上只能有一个方向,而默认方向是“正确”。您可以/应该手动设置方向。

根据您的用例,您还应该研究UIPanGestureRecognizers,因为它可以支持多向流,但是需要更多的设置。